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;
|
2011-11-28 20:10:19 +00:00
|
|
|
use \wcf\system\package\PackageDependencyHandler;
|
|
|
|
use \wcf\system\user\storage\UserStorageHandler;
|
2011-11-27 12:33:44 +00:00
|
|
|
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
|
|
|
|
2011-11-28 20:10:19 +00:00
|
|
|
$this->readRoom();
|
|
|
|
$this->readUserData();
|
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-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-12-04 21:46:50 +00:00
|
|
|
|
2011-12-10 17:05:21 +00:00
|
|
|
$this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, CHAT_LASTMESSAGES);
|
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-10 20:36:33 +00:00
|
|
|
if ($this->action == 'Log') {
|
|
|
|
//TODO: Initialise LogPage
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-03 16:37:20 +00:00
|
|
|
if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id'];
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads user data.
|
|
|
|
*/
|
|
|
|
public function readUserData() {
|
2011-12-13 22:02:00 +00:00
|
|
|
// TODO: Move this into ChatUtil
|
2011-11-28 20:10:19 +00:00
|
|
|
$ush = UserStorageHandler::getInstance();
|
|
|
|
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
|
|
|
|
|
|
|
|
// load storage
|
|
|
|
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
|
|
|
|
$data = $ush->getStorage(array(WCF::getUser()->userID), 'color', $packageID);
|
|
|
|
|
|
|
|
if ($data[WCF::getUser()->userID] === null) {
|
|
|
|
// set defaults
|
|
|
|
$data[WCF::getUser()->userID] = array(1 => 0xFF0000, 2 => 0x00FF00); // TODO: Change default values
|
|
|
|
$ush->update(WCF::getUser()->userID, 'color', serialize($data[WCF::getUser()->userID]), $packageID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// load existing data
|
|
|
|
$data[WCF::getUser()->userID] = unserialize($data[WCF::getUser()->userID]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->userData['color'] = $data[WCF::getUser()->userID];
|
2011-12-13 22:02:00 +00:00
|
|
|
|
|
|
|
$ush->update(WCF::getUser()->userID, 'roomID', $this->room->roomID, $packageID);
|
2011-11-27 12:33:44 +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-03 16:53:36 +00:00
|
|
|
if ($this->useTemplate) exit;
|
2011-12-03 16:37:20 +00:00
|
|
|
@header('Content-type: application/json');
|
|
|
|
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
|
|
|
}
|