From 0eb439e75f0e21f752f2b421f83ce7f96944ee18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 10 Dec 2011 17:20:57 +0100 Subject: [PATCH 1/3] Use fetchColumn to fetch the object-ids --- file/lib/data/chat/message/ChatMessageEditor.class.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/file/lib/data/chat/message/ChatMessageEditor.class.php b/file/lib/data/chat/message/ChatMessageEditor.class.php index 0e8a80f..b2f8a60 100644 --- a/file/lib/data/chat/message/ChatMessageEditor.class.php +++ b/file/lib/data/chat/message/ChatMessageEditor.class.php @@ -24,7 +24,7 @@ class ChatMessageEditor extends \wcf\data\DatabaseObjectEditor { * @return integer Number of deleted messages. */ public static function cleanup($lifetime = CHAT_ARCHIVETIME) { - $sql = "SELECT + $sql = "SELECT ".static::getDatabaseIndexName()." FROM ".static::getDatabaseTableName()." @@ -33,9 +33,7 @@ public static function cleanup($lifetime = CHAT_ARCHIVETIME) { $statement = \wcf\system\WCF::getDB()->prepareStatement($sql); $statement->execute(TIME_NOW - $lifetime); $objectIDs = array(); - while ($row = $statement->fetchArray()) { - $objectIDs[] = $row[static::getDatabaseIndexName()]; - } + while ($objectIDs[] = $statement->fetchColumn()); return static::deleteAll($objectIDs); } } From 12ccf89d30197f396bb88f5ef5d95a2ab6963156 Mon Sep 17 00:00:00 2001 From: max-m Date: Sat, 10 Dec 2011 21:36:33 +0100 Subject: [PATCH 2/3] Added possibility of using Chat/Log and Chat/Send as routes --- eventListener.xml | 12 +++++++ file/lib/page/ChatPage.class.php | 34 +++++++++++++------ .../listener/ChatRouteListener.class.php | 17 ++++++++++ package.xml | 2 ++ 4 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 eventListener.xml create mode 100644 file/lib/system/event/listener/ChatRouteListener.class.php diff --git a/eventListener.xml b/eventListener.xml new file mode 100644 index 0000000..612b7d8 --- /dev/null +++ b/eventListener.xml @@ -0,0 +1,12 @@ + + + + + wcf\system\request\RouteHandler + didInit + user + 0 + wcf\system\event\listener\ChatRouteListener + + + \ No newline at end of file diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 50cb493..6b9e551 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -20,6 +20,7 @@ class ChatPage extends AbstractPage { public $neededModules = array('CHAT_ACTIVE'); //public $neededPermissions = array('user.chat.canEnter'); public $joinMessage = null; + public $newestMessages = array(); public $room = null; public $roomID = 0; public $rooms = array(); @@ -35,6 +36,7 @@ public function assignVariables() { WCF::getTPL()->assign(array( 'chatVersion' => $this->chatVersion, 'joinMessage' => $this->joinMessage, + 'newestMessages' => $this->newestMessages, 'room' => $this->room, 'roomID' => $this->roomID, 'rooms' => $this->rooms, @@ -77,18 +79,11 @@ public function readData() { 'color1' => $this->userData['color'][1], 'color2' => $this->userData['color'][2] )); - if ($this->room->topic != '') { - chat\message\ChatMessageEditor::create(array( - 'roomID' => $this->room->roomID, - 'sender' => WCF::getUser()->userID, - 'time' => TIME_NOW, - 'type' => chat\message\ChatMessage::TYPE_INFORMATION, - 'message' => WCF::getLanguage()->getDynamicVariable($this->room->topic) - )); - } $this->readDefaultSmileys(); $this->readChatVersion(); + + $this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, 5); } /** @@ -105,7 +100,19 @@ public function readDefaultSmileys() { public function readParameters() { parent::readParameters(); - if (isset($_GET['id'])) $this->roomID = (int) $_GET['id']; + if ($this->action == 'Log') { + //TODO: Initialise LogPage + exit; + } + elseif($this->action == 'Send') { + //TODO: Safe message in database + exit; + } + + if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id']; + if (isset($_REQUEST['ajax'])) { + $this->useTemplate = false; + } } /** @@ -171,5 +178,12 @@ public function show() { // remove index breadcrumb WCF::getBreadcrumbs()->remove(0); parent::show(); + if ($this->useTemplate) exit; + @header('Content-type: application/json'); + echo \wcf\util\JSON::encode(array( + 'title' => WCF::getLanguage()->get($this->room->title), + 'topic' => WCF::getLanguage()->get($this->room->topic) + )); + exit; } } diff --git a/file/lib/system/event/listener/ChatRouteListener.class.php b/file/lib/system/event/listener/ChatRouteListener.class.php new file mode 100644 index 0000000..4f67713 --- /dev/null +++ b/file/lib/system/event/listener/ChatRouteListener.class.php @@ -0,0 +1,17 @@ +setSchema('/{controller}/{action}'); + $route->setParameterOption('controller', null, 'Chat'); + $route->setParameterOption('action', null, '(Log|Send)'); + $eventObj->addRoute($route); + } +} \ No newline at end of file diff --git a/package.xml b/package.xml index fc26253..15abc57 100644 --- a/package.xml +++ b/package.xml @@ -29,6 +29,7 @@ objectType.xml option.xml pagemenu.xml + eventListener.xml templatelistener.xml acloptions.xml @@ -41,6 +42,7 @@ objectType.xml option.xml pagemenu.xml + eventListener.xml templatelistener.xml acloptions.xml From 136bdde00614074d6917d1213a850b661087222e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 10 Dec 2011 21:51:44 +0100 Subject: [PATCH 3/3] Use language-specific title --- file/lib/data/chat/room/ChatRoom.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file/lib/data/chat/room/ChatRoom.class.php b/file/lib/data/chat/room/ChatRoom.class.php index 4a4ed0d..7611a5b 100644 --- a/file/lib/data/chat/room/ChatRoom.class.php +++ b/file/lib/data/chat/room/ChatRoom.class.php @@ -66,7 +66,7 @@ public function __toString() { * @see \wcf\system\request\IRouteController */ public function getTitle() { - return $this->title; + return WCF::getLanguage()->get($this->title); } /**