mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Add RoomCache class
This commit is contained in:
parent
41765c53be
commit
2d73af2b8c
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace be\bastelstu\wcf\chat;
|
namespace be\bastelstu\chat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles installation of Tims Chat.
|
* Handles installation of Tims Chat.
|
||||||
|
@ -26,7 +26,7 @@ final class Update {
|
|||||||
private $styles = null;
|
private $styles = null;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->rooms = \chat\data\room\Room::getCache();
|
$this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
||||||
$this->styles = \wcf\system\style\StyleHandler::getInstance()->getAvailableStyles();
|
$this->styles = \wcf\system\style\StyleHandler::getInstance()->getAvailableStyles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +53,10 @@ public function validateSend() {
|
|||||||
$this->parameters['userData']['away'] = \chat\util\ChatUtil::readUserData('away');
|
$this->parameters['userData']['away'] = \chat\util\ChatUtil::readUserData('away');
|
||||||
|
|
||||||
// read and validate room
|
// read and validate room
|
||||||
$cache = room\Room::getCache();
|
$this->parameters['room'] = room\RoomCache::getInstance()->getRoom($this->parameters['userData']['roomID']);
|
||||||
if (!isset($cache[$this->parameters['userData']['roomID']])) throw new \wcf\system\exception\IllegalLinkException();
|
if ($this->parameters['room'] === null) throw new \wcf\system\exception\IllegalLinkException();
|
||||||
$this->parameters['room'] = $cache[$this->parameters['userData']['roomID']];
|
if (!$this->parameters['room']->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
||||||
|
if (!$this->parameters['room']->canWrite()) throw new \wcf\system\exception\PermissionDeniedException();
|
||||||
if (!$this->parameters['room']->canEnter() || !$this->parameters['room']->canWrite()) throw new \wcf\system\exception\PermissionDeniedException();
|
|
||||||
|
|
||||||
// read parameters
|
// read parameters
|
||||||
$this->readString('text');
|
$this->readString('text');
|
||||||
|
@ -126,19 +126,16 @@ public function updatePosition() {
|
|||||||
public function validateGetRoomList() {
|
public function validateGetRoomList() {
|
||||||
if (!MODULE_CHAT) throw new \wcf\system\exception\IllegalLinkException();
|
if (!MODULE_CHAT) throw new \wcf\system\exception\IllegalLinkException();
|
||||||
|
|
||||||
$rooms = Room::getCache();
|
|
||||||
$roomID = ChatUtil::readUserData('roomID');
|
$roomID = ChatUtil::readUserData('roomID');
|
||||||
if (!isset($rooms[$roomID])) {
|
$this->parameters['room'] = RoomCache::getInstance()->getRoom($roomID);
|
||||||
throw new \wcf\system\exception\IllegalLinkException();
|
if ($this->parameters['room'] === null) throw new \wcf\system\exception\IllegalLinkException();
|
||||||
}
|
|
||||||
$this->parameters['room'] = $rooms[$roomID];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the available rooms.
|
* Returns the available rooms.
|
||||||
*/
|
*/
|
||||||
public function getRoomList() {
|
public function getRoomList() {
|
||||||
$rooms = Room::getCache();
|
$rooms = RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($rooms as $room) {
|
foreach ($rooms as $room) {
|
||||||
@ -165,9 +162,8 @@ public function validateLeave() {
|
|||||||
|
|
||||||
unset($this->parameters['user']);
|
unset($this->parameters['user']);
|
||||||
|
|
||||||
$rooms = Room::getCache();
|
|
||||||
$roomID = ChatUtil::readUserData('roomID');
|
$roomID = ChatUtil::readUserData('roomID');
|
||||||
if (!isset($rooms[$roomID])) throw new \wcf\system\exception\IllegalLinkException();
|
if (RoomCache::getInstance()->getRoom($roomID) === null) throw new \wcf\system\exception\IllegalLinkException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,11 +175,9 @@ public function leave() {
|
|||||||
$this->parameters['user'] = WCF::getUser();
|
$this->parameters['user'] = WCF::getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rooms = Room::getCache();
|
|
||||||
|
|
||||||
$roomID = ChatUtil::readUserData('roomID', $this->parameters['user']);
|
$roomID = ChatUtil::readUserData('roomID', $this->parameters['user']);
|
||||||
if (!isset($rooms[$roomID])) throw new \wcf\system\exception\UserInputException();
|
$room = RoomCache::getInstance()->getRoom($roomID);
|
||||||
$activeRoom = $rooms[$roomID];
|
if ($room === null) throw new \wcf\system\exception\UserInputException();
|
||||||
|
|
||||||
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
||||||
$userData['color'] = ChatUtil::readUserData('color', $this->parameters['user']);
|
$userData['color'] = ChatUtil::readUserData('color', $this->parameters['user']);
|
||||||
@ -191,7 +185,7 @@ public function leave() {
|
|||||||
// leave message
|
// leave message
|
||||||
$messageAction = new \chat\data\message\MessageAction(array(), 'create', array(
|
$messageAction = new \chat\data\message\MessageAction(array(), 'create', array(
|
||||||
'data' => array(
|
'data' => array(
|
||||||
'roomID' => $activeRoom->roomID,
|
'roomID' => $room->roomID,
|
||||||
'sender' => $this->parameters['user']->userID,
|
'sender' => $this->parameters['user']->userID,
|
||||||
'username' => $this->parameters['user']->username,
|
'username' => $this->parameters['user']->username,
|
||||||
'time' => TIME_NOW,
|
'time' => TIME_NOW,
|
||||||
@ -235,7 +229,7 @@ public function validateGetDashboardRoomList() {
|
|||||||
* Returns dashboard roomlist.
|
* Returns dashboard roomlist.
|
||||||
*/
|
*/
|
||||||
public function getDashboardRoomList() {
|
public function getDashboardRoomList() {
|
||||||
$rooms = Room::getCache();
|
$rooms = RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
foreach ($rooms as $key => $room) {
|
foreach ($rooms as $key => $room) {
|
||||||
if (!$room->canEnter()) unset($rooms[$key]);
|
if (!$room->canEnter()) unset($rooms[$key]);
|
||||||
|
49
file/lib/data/room/RoomCache.class.php
Normal file
49
file/lib/data/room/RoomCache.class.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
namespace chat\data\room;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the room cache.
|
||||||
|
*
|
||||||
|
* @author Tim Düsterhus
|
||||||
|
* @copyright 2010-2013 Tim Düsterhus
|
||||||
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||||
|
* @package be.bastelstu.chat
|
||||||
|
* @subpackage data.room
|
||||||
|
*/
|
||||||
|
class RoomCache extends \wcf\system\SingletonFactory {
|
||||||
|
/**
|
||||||
|
* list of cached rooms
|
||||||
|
* @var array<\chat\data\room\Room>
|
||||||
|
*/
|
||||||
|
protected $rooms = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see wcf\system\SingletonFactory::init()
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->rooms = \chat\system\cache\builder\RoomCacheBuilder::getInstance()->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a specific room.
|
||||||
|
*
|
||||||
|
* @param integer $roomID
|
||||||
|
* @return \chat\data\room\Room
|
||||||
|
*/
|
||||||
|
public function getRoom($roomID) {
|
||||||
|
if (isset($this->rooms[$roomID])) {
|
||||||
|
return $this->rooms[$roomID];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all rooms.
|
||||||
|
*
|
||||||
|
* @return array<\chat\data\room\Room>
|
||||||
|
*/
|
||||||
|
public function getRooms() {
|
||||||
|
return $this->rooms;
|
||||||
|
}
|
||||||
|
}
|
@ -174,7 +174,7 @@ public function readParameters() {
|
|||||||
* Reads room data.
|
* Reads room data.
|
||||||
*/
|
*/
|
||||||
public function readRoom() {
|
public function readRoom() {
|
||||||
$this->rooms = data\room\Room::getCache();
|
$this->rooms = data\room\RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
if ($this->roomID === 0) {
|
if ($this->roomID === 0) {
|
||||||
// no room given
|
// no room given
|
||||||
|
@ -77,11 +77,9 @@ public function readParameters() {
|
|||||||
public function readData() {
|
public function readData() {
|
||||||
parent::readData();
|
parent::readData();
|
||||||
|
|
||||||
$cache = data\room\Room::getCache();
|
$this->room = data\room\RoomCache::getInstance()->getRoom($this->roomID);
|
||||||
if (!isset($cache[$this->roomID])) throw new IllegalLinkException();
|
if (!$this->room) throw new IllegalLinkException();
|
||||||
|
if (!$this->room->canEnter()) throw new PermissionDeniedException();
|
||||||
$this->room = $cache[$this->roomID];
|
|
||||||
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
|
||||||
|
|
||||||
// TODO: actually read the correct messages
|
// TODO: actually read the correct messages
|
||||||
$this->messages = data\message\MessageList::getNewestMessages($this->room, 150);
|
$this->messages = data\message\MessageList::getNewestMessages($this->room, 150);
|
||||||
|
@ -94,10 +94,9 @@ public function readMessages() {
|
|||||||
*/
|
*/
|
||||||
public function readRoom() {
|
public function readRoom() {
|
||||||
$roomID = \chat\util\ChatUtil::readUserData('roomID');
|
$roomID = \chat\util\ChatUtil::readUserData('roomID');
|
||||||
$cache = data\room\Room::getCache();
|
|
||||||
if (!isset($cache[$roomID])) throw new IllegalLinkException();
|
|
||||||
|
|
||||||
$this->room = $cache[$roomID];
|
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom($roomID);
|
||||||
|
if (!$this->room) throw new IllegalLinkException();
|
||||||
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Room
|
// Room
|
||||||
$room = new \chat\data\room\Room(ChatUtil::readUserData('roomID', $this->user));
|
$room = \chat\data\room\RoomCache::getInstance()->getRoom(ChatUtil::readUserData('roomID', $this->user));
|
||||||
if ($room->roomID && $room->canEnter()) {
|
if ($room->roomID && $room->canEnter()) {
|
||||||
$this->lines[WCF::getLanguage()->get('chat.general.room')] = $room->getTitle();
|
$this->lines[WCF::getLanguage()->get('chat.general.room')] = $room->getTitle();
|
||||||
}
|
}
|
||||||
@ -52,7 +52,11 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
|||||||
if (!$typeSuspension->isValid()) continue;
|
if (!$typeSuspension->isValid()) continue;
|
||||||
|
|
||||||
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
|
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
|
||||||
$this->lines[$typeSuspension->type.'-'.$typeSuspension->roomID] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')));
|
$name = WCF::getLanguage()->getDynamicVariable('chat.information.suspension', array(
|
||||||
|
'suspension' => $typeSuspension,
|
||||||
|
'room' => \chat\data\room\RoomCache::getInstance()->getRoom($typeSuspension->roomID)
|
||||||
|
));
|
||||||
|
$this->lines[$name] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public function getType() {
|
|||||||
* @see \chat\system\command\ICommand::getMessage()
|
* @see \chat\system\command\ICommand::getMessage()
|
||||||
*/
|
*/
|
||||||
public function getMessage() {
|
public function getMessage() {
|
||||||
$rooms = \chat\data\room\Room::getCache();
|
$rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
foreach ($rooms as $room) {
|
foreach ($rooms as $room) {
|
||||||
$users = $room->getUsers();
|
$users = $room->getUsers();
|
||||||
|
@ -27,7 +27,7 @@ public function init(\wcf\data\dashboard\box\DashboardBox $box, \wcf\page\IPage
|
|||||||
if (!MODULE_CHAT) return;
|
if (!MODULE_CHAT) return;
|
||||||
if (!\wcf\system\WCF::getUser()->userID) return;
|
if (!\wcf\system\WCF::getUser()->userID) return;
|
||||||
|
|
||||||
$this->rooms = data\room\Room::getCache();
|
$this->rooms = data\room\RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
foreach ($this->rooms as $key => $room) {
|
foreach ($this->rooms as $key => $room) {
|
||||||
if (!$room->canEnter()) unset($this->rooms[$key]);
|
if (!$room->canEnter()) unset($this->rooms[$key]);
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
* @subpackage system.menu.page
|
* @subpackage system.menu.page
|
||||||
*/
|
*/
|
||||||
class ChatPageMenuItemProvider extends \wcf\system\menu\page\DefaultPageMenuItemProvider {
|
class ChatPageMenuItemProvider extends \wcf\system\menu\page\DefaultPageMenuItemProvider {
|
||||||
|
/**
|
||||||
|
* room that the menu item points to
|
||||||
|
*
|
||||||
|
* @var \chat\data\room\Room
|
||||||
|
*/
|
||||||
protected $room = null;
|
protected $room = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,9 +27,9 @@ public function isVisible() {
|
|||||||
// guests are not supported
|
// guests are not supported
|
||||||
if (!\wcf\system\WCF::getUser()->userID) return false;
|
if (!\wcf\system\WCF::getUser()->userID) return false;
|
||||||
|
|
||||||
$cache = \chat\data\room\Room::getCache();
|
$rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
foreach ($cache as $this->room) {
|
foreach ($rooms as $this->room) {
|
||||||
if ($this->room->canEnter()) {
|
if ($this->room->canEnter()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ public function cache(\wcf\data\user\online\UserOnline $user) {}
|
|||||||
* @see \wcf\system\user\online\location\IUserOnlineLocation::get()
|
* @see \wcf\system\user\online\location\IUserOnlineLocation::get()
|
||||||
*/
|
*/
|
||||||
public function get(\wcf\data\user\online\UserOnline $user, $languageVariable = '') {
|
public function get(\wcf\data\user\online\UserOnline $user, $languageVariable = '') {
|
||||||
$cache = data\room\Room::getCache();
|
$rooms = data\room\RoomCache::getInstance()->getRooms();
|
||||||
|
|
||||||
if (isset($cache[$user->objectID])) {
|
if (isset($cache[$user->objectID])) {
|
||||||
if ($cache[$user->objectID]->canEnter()) {
|
if ($cache[$user->objectID]->canEnter()) {
|
||||||
return \wcf\system\WCF::getLanguage()->getDynamicVariable($languageVariable, array(
|
return \wcf\system\WCF::getLanguage()->getDynamicVariable($languageVariable, array(
|
||||||
|
@ -90,6 +90,7 @@
|
|||||||
|
|
||||||
<item name="chat.general.information"><![CDATA[Information]]></item>
|
<item name="chat.general.information"><![CDATA[Information]]></item>
|
||||||
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
|
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
|
||||||
|
<item name="chat.information.suspension"><![CDATA[{lang}chat.suspension.{$suspension->type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]></item>
|
||||||
</category>
|
</category>
|
||||||
|
|
||||||
<category name="chat.header">
|
<category name="chat.header">
|
||||||
@ -116,8 +117,14 @@
|
|||||||
<item name="chat.message.color.success"><![CDATA[Die Farbe wurde erfolgreich geändert.]]></item>
|
<item name="chat.message.color.success"><![CDATA[Die Farbe wurde erfolgreich geändert.]]></item>
|
||||||
</category>
|
</category>
|
||||||
|
|
||||||
|
<category name="chat.suspension">
|
||||||
|
<item name="chat.suspension.1"><![CDATA[Knebel]]></item>
|
||||||
|
<item name="chat.suspension.2"><![CDATA[Bann]]></item>
|
||||||
|
</category>
|
||||||
|
|
||||||
<!-- I18N Values -->
|
<!-- I18N Values -->
|
||||||
<category name="chat.room">
|
<category name="chat.room">
|
||||||
|
<item name="chat.room.global"><![CDATA[Global]]></item>
|
||||||
<item name="chat.room.title1"><![CDATA[Hauptchat]]></item>
|
<item name="chat.room.title1"><![CDATA[Hauptchat]]></item>
|
||||||
<item name="chat.room.topic1"><![CDATA[Vielen Dank, dass Sie sich für Tims Chat entschieden haben. Bitte besuchen Sie das ACP um diesen Text anzupassen.]]></item>
|
<item name="chat.room.topic1"><![CDATA[Vielen Dank, dass Sie sich für Tims Chat entschieden haben. Bitte besuchen Sie das ACP um diesen Text anzupassen.]]></item>
|
||||||
<item name="chat.room.titleTemp"><![CDATA[Raum_{$roomID}]]></item>
|
<item name="chat.room.titleTemp"><![CDATA[Raum_{$roomID}]]></item>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
|
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
|
||||||
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
|
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
|
||||||
<isapplication>1</isapplication>
|
<isapplication>1</isapplication>
|
||||||
<version>3.0.0 Alpha 26</version><!-- Codename: Codenames are overrated -->
|
<version>3.0.0 Alpha 28</version><!-- Codename: Codenames are overrated -->
|
||||||
<date>2011-11-26</date>
|
<date>2011-11-26</date>
|
||||||
</packageinformation>
|
</packageinformation>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user