diff --git a/file/acp/be.bastelstu.chat.install.php b/file/acp/be.bastelstu.chat.install.php index 56f88d1..194e4e9 100644 --- a/file/acp/be.bastelstu.chat.install.php +++ b/file/acp/be.bastelstu.chat.install.php @@ -1,5 +1,5 @@ rooms = \chat\data\room\Room::getCache(); + $this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); $this->styles = \wcf\system\style\StyleHandler::getInstance()->getAvailableStyles(); } diff --git a/file/lib/data/message/MessageAction.class.php b/file/lib/data/message/MessageAction.class.php index ffe341e..65f9972 100644 --- a/file/lib/data/message/MessageAction.class.php +++ b/file/lib/data/message/MessageAction.class.php @@ -53,11 +53,10 @@ public function validateSend() { $this->parameters['userData']['away'] = \chat\util\ChatUtil::readUserData('away'); // read and validate room - $cache = room\Room::getCache(); - if (!isset($cache[$this->parameters['userData']['roomID']])) throw new \wcf\system\exception\IllegalLinkException(); - $this->parameters['room'] = $cache[$this->parameters['userData']['roomID']]; - - if (!$this->parameters['room']->canEnter() || !$this->parameters['room']->canWrite()) throw new \wcf\system\exception\PermissionDeniedException(); + $this->parameters['room'] = room\RoomCache::getInstance()->getRoom($this->parameters['userData']['roomID']); + if ($this->parameters['room'] === null) throw new \wcf\system\exception\IllegalLinkException(); + if (!$this->parameters['room']->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); + if (!$this->parameters['room']->canWrite()) throw new \wcf\system\exception\PermissionDeniedException(); // read parameters $this->readString('text'); diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index e1a7d93..21da859 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -126,19 +126,16 @@ public function updatePosition() { public function validateGetRoomList() { if (!MODULE_CHAT) throw new \wcf\system\exception\IllegalLinkException(); - $rooms = Room::getCache(); $roomID = ChatUtil::readUserData('roomID'); - if (!isset($rooms[$roomID])) { - throw new \wcf\system\exception\IllegalLinkException(); - } - $this->parameters['room'] = $rooms[$roomID]; + $this->parameters['room'] = RoomCache::getInstance()->getRoom($roomID); + if ($this->parameters['room'] === null) throw new \wcf\system\exception\IllegalLinkException(); } /** * Returns the available rooms. */ public function getRoomList() { - $rooms = Room::getCache(); + $rooms = RoomCache::getInstance()->getRooms(); $result = array(); foreach ($rooms as $room) { @@ -165,9 +162,8 @@ public function validateLeave() { unset($this->parameters['user']); - $rooms = Room::getCache(); $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(); } - $rooms = Room::getCache(); - $roomID = ChatUtil::readUserData('roomID', $this->parameters['user']); - if (!isset($rooms[$roomID])) throw new \wcf\system\exception\UserInputException(); - $activeRoom = $rooms[$roomID]; + $room = RoomCache::getInstance()->getRoom($roomID); + if ($room === null) throw new \wcf\system\exception\UserInputException(); if (CHAT_DISPLAY_JOIN_LEAVE) { $userData['color'] = ChatUtil::readUserData('color', $this->parameters['user']); @@ -191,7 +185,7 @@ public function leave() { // leave message $messageAction = new \chat\data\message\MessageAction(array(), 'create', array( 'data' => array( - 'roomID' => $activeRoom->roomID, + 'roomID' => $room->roomID, 'sender' => $this->parameters['user']->userID, 'username' => $this->parameters['user']->username, 'time' => TIME_NOW, @@ -235,7 +229,7 @@ public function validateGetDashboardRoomList() { * Returns dashboard roomlist. */ public function getDashboardRoomList() { - $rooms = Room::getCache(); + $rooms = RoomCache::getInstance()->getRooms(); foreach ($rooms as $key => $room) { if (!$room->canEnter()) unset($rooms[$key]); diff --git a/file/lib/data/room/RoomCache.class.php b/file/lib/data/room/RoomCache.class.php new file mode 100644 index 0000000..b50126e --- /dev/null +++ b/file/lib/data/room/RoomCache.class.php @@ -0,0 +1,49 @@ + + * @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; + } +} diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 024081a..36678cd 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -174,7 +174,7 @@ public function readParameters() { * Reads room data. */ public function readRoom() { - $this->rooms = data\room\Room::getCache(); + $this->rooms = data\room\RoomCache::getInstance()->getRooms(); if ($this->roomID === 0) { // no room given diff --git a/file/lib/page/LogPage.class.php b/file/lib/page/LogPage.class.php index 5a9fa50..b528281 100644 --- a/file/lib/page/LogPage.class.php +++ b/file/lib/page/LogPage.class.php @@ -77,11 +77,9 @@ public function readParameters() { public function readData() { parent::readData(); - $cache = data\room\Room::getCache(); - if (!isset($cache[$this->roomID])) throw new IllegalLinkException(); - - $this->room = $cache[$this->roomID]; - if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); + $this->room = data\room\RoomCache::getInstance()->getRoom($this->roomID); + if (!$this->room) throw new IllegalLinkException(); + if (!$this->room->canEnter()) throw new PermissionDeniedException(); // TODO: actually read the correct messages $this->messages = data\message\MessageList::getNewestMessages($this->room, 150); diff --git a/file/lib/page/NewMessagesPage.class.php b/file/lib/page/NewMessagesPage.class.php index 066eb3b..ba2424c 100644 --- a/file/lib/page/NewMessagesPage.class.php +++ b/file/lib/page/NewMessagesPage.class.php @@ -94,10 +94,9 @@ public function readMessages() { */ public function readRoom() { $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(); } diff --git a/file/lib/system/command/commands/InfoCommand.class.php b/file/lib/system/command/commands/InfoCommand.class.php index e4288c4..a904e0c 100644 --- a/file/lib/system/command/commands/InfoCommand.class.php +++ b/file/lib/system/command/commands/InfoCommand.class.php @@ -39,7 +39,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) } // 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()) { $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; $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'))); } } diff --git a/file/lib/system/command/commands/WhereCommand.class.php b/file/lib/system/command/commands/WhereCommand.class.php index eece31a..e7a81b6 100644 --- a/file/lib/system/command/commands/WhereCommand.class.php +++ b/file/lib/system/command/commands/WhereCommand.class.php @@ -22,7 +22,7 @@ public function getType() { * @see \chat\system\command\ICommand::getMessage() */ public function getMessage() { - $rooms = \chat\data\room\Room::getCache(); + $rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); foreach ($rooms as $room) { $users = $room->getUsers(); diff --git a/file/lib/system/dashboard/box/OnlineListDashboardBox.class.php b/file/lib/system/dashboard/box/OnlineListDashboardBox.class.php index 4f87ffc..763e6c0 100644 --- a/file/lib/system/dashboard/box/OnlineListDashboardBox.class.php +++ b/file/lib/system/dashboard/box/OnlineListDashboardBox.class.php @@ -27,7 +27,7 @@ public function init(\wcf\data\dashboard\box\DashboardBox $box, \wcf\page\IPage if (!MODULE_CHAT) 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) { if (!$room->canEnter()) unset($this->rooms[$key]); diff --git a/file/lib/system/menu/page/ChatPageMenuItemProvider.class.php b/file/lib/system/menu/page/ChatPageMenuItemProvider.class.php index a769528..7ba3ff0 100644 --- a/file/lib/system/menu/page/ChatPageMenuItemProvider.class.php +++ b/file/lib/system/menu/page/ChatPageMenuItemProvider.class.php @@ -11,6 +11,11 @@ * @subpackage system.menu.page */ class ChatPageMenuItemProvider extends \wcf\system\menu\page\DefaultPageMenuItemProvider { + /** + * room that the menu item points to + * + * @var \chat\data\room\Room + */ protected $room = null; /** @@ -22,9 +27,9 @@ public function isVisible() { // guests are not supported 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()) { return true; } diff --git a/file/lib/system/user/online/location/ChatLocation.class.php b/file/lib/system/user/online/location/ChatLocation.class.php index 65b1edc..c363e5e 100644 --- a/file/lib/system/user/online/location/ChatLocation.class.php +++ b/file/lib/system/user/online/location/ChatLocation.class.php @@ -21,7 +21,8 @@ public function cache(\wcf\data\user\online\UserOnline $user) {} * @see \wcf\system\user\online\location\IUserOnlineLocation::get() */ 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 ($cache[$user->objectID]->canEnter()) { return \wcf\system\WCF::getLanguage()->getDynamicVariable($languageVariable, array( diff --git a/language/de.xml b/language/de.xml index f8976d9..64a4659 100644 --- a/language/de.xml +++ b/language/de.xml @@ -90,6 +90,7 @@ + type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]> @@ -116,8 +117,14 @@ + + + + + + diff --git a/package.xml b/package.xml index 693862e..92bed59 100644 --- a/package.xml +++ b/package.xml @@ -5,7 +5,7 @@ 1 - 3.0.0 Alpha 26 + 3.0.0 Alpha 28 2011-11-26