From 6fa0d3a3f268366d5b193e13c3de251a98e3e8ab Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 22 Jun 2013 16:44:10 +0200 Subject: [PATCH 01/13] Remove chat log from frontend This commit is a preparation for moving the chat log into ACP --- acpMenu.xml | 7 ++++++ file/js/be.bastelstu.Chat.Log.coffee | 35 ---------------------------- template/chat.tpl | 7 ------ template/navigationInclude.tpl | 7 ------ userGroupOption.xml | 12 +++++----- 5 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 file/js/be.bastelstu.Chat.Log.coffee delete mode 100644 template/navigationInclude.tpl diff --git a/acpMenu.xml b/acpMenu.xml index 7717827..39b51ca 100644 --- a/acpMenu.xml +++ b/acpMenu.xml @@ -22,5 +22,12 @@ admin.chat.canAddRoom 2 + + + + chat.acp.menu.link.chat + admin.chat.canReadLog + 4 + diff --git a/file/js/be.bastelstu.Chat.Log.coffee b/file/js/be.bastelstu.Chat.Log.coffee deleted file mode 100644 index b3bc858..0000000 --- a/file/js/be.bastelstu.Chat.Log.coffee +++ /dev/null @@ -1,35 +0,0 @@ -### -# be.bastelstu.WCF.Chat.Log -# -# @author Tim Düsterhus -# @copyright 2010-2013 Tim Düsterhus -# @license Creative Commons Attribution-NonCommercial-ShareAlike -# @package be.bastelstu.chat -### - -(($, window) -> - be.bastelstu.Chat.Log = be.bastelstu.Chat.extend - init: (@chat) -> - handleMessages: (messages) -> - # Insert the messages - for message in messages - @events.newMessage.fire message - - output = @chat.messageTemplate.fetch message - li = $ '
  • ' - li.addClass 'timsChatMessage timsChatMessage'+message.type - li.addClass 'ownMessage' if message.sender is WCF.User.userID - li.append output - - li.appendTo $ '#timsChatLog .timsChatMessageContainer > ul' - - be.bastelstu.Chat.Log.loadOverlay = () -> - if !$.wcfIsset 'timsChatLogDialog' - container = $ '
    ' - $('#content').append container - - # TODO: Proper path - $('#timsChatLogDialog').load 'http://127.0.0.1/wbb/wbb4/index.php/Chat/Log/1-Hauptchat/', () -> - WCF.showDialog 'timsChatLogDialog', - title: 'Log' -)(jQuery, @) diff --git a/template/chat.tpl b/template/chat.tpl index 09296cb..9d7f843 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -50,12 +50,6 @@ title: ' {if SHOW_VERSION_NUMBER} {PACKAGE_VERSION}{/if}' }); }); - - $('#chatLogLink').click(function (event) { - event.preventDefault(); - - be.bastelstu.Chat.Log.loadOverlay(); - }); }); })(jQuery, this); //]]> @@ -85,7 +79,6 @@ {capture assign='sidebar'}{include application='chat' file='sidebar'}{/capture} - {capture assign='headerNavigation'}{include application='chat' file='navigationInclude'}{/capture} {include file='header' sandbox=false sidebarOrientation='right'}
    {$room->topic|language}
    diff --git a/template/navigationInclude.tpl b/template/navigationInclude.tpl deleted file mode 100644 index 92695e0..0000000 --- a/template/navigationInclude.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{if $__wcf->session->getPermission('mod.chat.canReadLog')} -
  • - - {lang}chat.general.protocol{/lang} - -
  • -{/if} diff --git a/userGroupOption.xml b/userGroupOption.xml index 5c7150b..e12649c 100644 --- a/userGroupOption.xml +++ b/userGroupOption.xml @@ -80,12 +80,6 @@ 0 1 - + \ No newline at end of file From b1277178ca47ac8be03ea9a765fc728085e5e894 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Wed, 24 Jul 2013 21:59:34 +0200 Subject: [PATCH 02/13] Fix acp menu item link for message log --- acpMenu.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acpMenu.xml b/acpMenu.xml index 5ca08a2..075fa79 100644 --- a/acpMenu.xml +++ b/acpMenu.xml @@ -31,7 +31,7 @@ - + chat.acp.menu.link.chat admin.chat.canReadLog 4 From 495680c3d359e504186c1844a96d0a8f9139d14d Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sun, 28 Jul 2013 23:27:28 +0200 Subject: [PATCH 03/13] Add message log to ACP. --- acptemplate/messageLog.tpl | 77 +++++++++++ file/lib/acp/page/MessageLogPage.class.php | 144 +++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 acptemplate/messageLog.tpl create mode 100644 file/lib/acp/page/MessageLogPage.class.php diff --git a/acptemplate/messageLog.tpl b/acptemplate/messageLog.tpl new file mode 100644 index 0000000..97c6341 --- /dev/null +++ b/acptemplate/messageLog.tpl @@ -0,0 +1,77 @@ +{include file='header' pageTitle='chat.acp.log.title'} + +
    +

    {lang}{@$pageTitle}{/lang}

    +
    + +
    +
    +
    + {lang}wcf.global.filter{/lang} + +
    +
    +
    + +
    +
    + + +
    +
    + + {if $errorField == 'date'} + + {lang}chat.acp.log.date.error.{$errorType}{/lang} + + {/if} +
    + +
    +
    + +
    + +
    +
    + +{if $messages|count == 0} + {if $errorField === ""} +

    {lang}wcf.global.noItems{/lang}

    + {/if} +{else} +
    +
    +

    {lang}chat.acp.log.title{/lang} {#$messages|count}

    +
    + + + + + + + + + + + + + {foreach from=$messages item='message'} + + + + + + + + {/foreach} + +
    {lang}wcf.global.objectID{/lang}{lang}chat.general.time{/lang}{lang}wcf.user.username{/lang}{lang}chat.acp.log.message{/lang}
    {$message->messageID}{$message->time|date:'H:i:s'}

    {@$message->getUserProfile()->getAvatar()->getImageTag(24)}

    {$message->username}{@$message->getFormattedMessage('text/simplified-html')}
    +
    +{/if} + +{include file='footer'} diff --git a/file/lib/acp/page/MessageLogPage.class.php b/file/lib/acp/page/MessageLogPage.class.php new file mode 100644 index 0000000..ccfc254 --- /dev/null +++ b/file/lib/acp/page/MessageLogPage.class.php @@ -0,0 +1,144 @@ + + * @package be.bastelstu.chat + * @subpackage acp.page + */ +class MessageLogPage extends \wcf\page\AbstractPage { + /** + * @see \wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'chat.acp.menu.link.log'; + + /** + * @see \wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array( + 'mod.chat.canReadLog' + ); + + /** + * name of error field + * @var string + */ + public $errorField = ''; + + /** + * error type + * @var string + */ + public $errorType = ''; + + /** + * messages for the given day + * + * @var array<\chat\data\message\Message> + */ + public $messages = array(); + + /** + * given roomID + * + * @var integer + */ + public $roomID = 0; + + /** + * given date + * + * @var integer + */ + public $date = 0; + + /** + * active room + * + * @var \chat\data\room\Room + */ + public $room = null; + + /** + * available rooms + * + * @var array<\chat\data\room\Room> + */ + public $rooms = array(); + + /** + * @see \wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + try { + if($this->date > TIME_NOW) { + throw new \wcf\system\exception\UserInputException('date', 'inFuture'); + } + } catch(\wcf\system\exception\UserInputException $e) { + $this->errorField = $e->getField(); + $this->errorType = $e->getType(); + return; + } + + try { + if($this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { + throw new \wcf\system\exception\UserInputException('date', 'tooLongAgo'); + } + } catch(\wcf\system\exception\UserInputException $e) { + $this->errorField = $e->getField(); + $this->errorType = $e->getType(); + return; + } + + $this->messages = \chat\data\message\ViewableMessageList::getMessagesBetween($this->room, $this->date, $this->date + 86399); + } + + /** + * @see \wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + $this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); + + foreach($this->rooms as $id => $room) { + if (!$room->permanent) + unset($this->rooms[$key]); + } + + if (isset($_REQUEST['id'])) $this->roomID = intval($_REQUEST['id']); + else $this->roomID = reset($this->rooms)->roomID; + + $this->room = \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); + + if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + + if (isset($_REQUEST['date'])) $date = $_REQUEST['date'].' 00:00:00'; + else $date = 'today 00:00:00'; + $this->date = @strtotime($date); + if ($this->date === false) throw new \wcf\system\exception\IllegalLinkException(); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'messages' => $this->messages, + 'rooms' => $this->rooms, + 'room' => $this->room, + 'date' => $this->date, + 'errorField' => $this->errorField, + 'errorType' => $this->errorType + )); + } +} From 75c09e2a5dfaf8e04de6014b4e9450fe703007b7 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 30 Jul 2013 00:19:02 +0200 Subject: [PATCH 04/13] Fixup last commit #495680c3d359e504186c These changes should have been in the last commit too. --- file/lib/data/message/Message.class.php | 4 +- file/lib/data/message/MessageList.class.php | 19 +++++ file/lib/page/LogPage.class.php | 87 --------------------- language/de.xml | 8 ++ 4 files changed, 29 insertions(+), 89 deletions(-) delete mode 100644 file/lib/page/LogPage.class.php diff --git a/file/lib/data/message/Message.class.php b/file/lib/data/message/Message.class.php index f4f70e6..9464f31 100644 --- a/file/lib/data/message/Message.class.php +++ b/file/lib/data/message/Message.class.php @@ -70,7 +70,7 @@ public function __toString() { public function getFormattedMessage($type = 'text/html') { $message = $this->message; $messageParser = \wcf\system\bbcode\MessageParser::getInstance(); - $messageParser->setOutputType('text/html'); + $messageParser->setOutputType($type); switch ($this->type) { case self::TYPE_JOIN: @@ -91,7 +91,7 @@ public function getFormattedMessage($type = 'text/html') { case self::TYPE_NORMAL: case self::TYPE_ME: default: - if ($type !== 'text/html') return $message; + if ($type === 'text/plain') return $message; $message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false); break; diff --git a/file/lib/data/message/MessageList.class.php b/file/lib/data/message/MessageList.class.php index 07b6c7d..2cee65b 100644 --- a/file/lib/data/message/MessageList.class.php +++ b/file/lib/data/message/MessageList.class.php @@ -60,4 +60,23 @@ public static function getMessagesSince(\chat\data\room\Room $room, $since) { $messageList->readObjects(); return $messageList->getObjects(); } + + /** + * Reads the message between the given timestamps for the given room. + * + * @param \chat\data\room\Room $room + * @param integer $start + * @param integer $end + * @return array<\chat\data\message\Message> + */ + public static function getMessagesBetween(\chat\data\room\Room $room, $start, $end) { + $messageList = new static(); + $messageList->sqlOrderBy = "message.messageID ASC"; + $messageList->getConditionBuilder()->add('message.receiver IS NULL', array()); + $messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID)); + $messageList->getConditionBuilder()->add('message.time BETWEEN ? AND ?', array($start, $end)); + + $messageList->readObjects(); + return $messageList->getObjects(); + } } diff --git a/file/lib/page/LogPage.class.php b/file/lib/page/LogPage.class.php deleted file mode 100644 index b528281..0000000 --- a/file/lib/page/LogPage.class.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @package be.bastelstu.chat - * @subpackage page - */ -class LogPage extends \wcf\page\AbstractPage { - /** - * @see wcf\page\AbstractPage::$loginRequired - */ - public $loginRequired = true; - - /** - * TODO: comment this - * - * @var array<\wcf\data\chat\message\ChatMessage> - */ - public $messages = array(); - - /** - * @see \wcf\page\AbstractPage::$neededModules - */ - public $neededModules = array('MODULE_CHAT'); - - /** - * @see \wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('mod.chat.canReadLog'); - - /** - * given roomID - * @var integer - */ - public $roomID = 0; - - /** - * given room - * @var \chat\data\room\Chat - */ - public $room = null; - - /** - * @see \wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'messages' => $this->messages, - 'room' => $this->room, - 'roomID' => $this->roomID - )); - } - - /** - * @see \wcf\page\IPage::readParameters() - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['id'])) $this->roomID = intval($_REQUEST['id']); - } - - /** - * @see \wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - $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/language/de.xml b/language/de.xml index c46fc3f..459c093 100644 --- a/language/de.xml +++ b/language/de.xml @@ -21,8 +21,16 @@ revokerUsername}]]> + + + + + + + + From 3a44dbe8503fa240b88e39bcba599373f641286a Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 30 Jul 2013 00:23:14 +0200 Subject: [PATCH 05/13] Prepare messageLog.tpl for using tab menus This is work in progress, currently not a single message is being displayed --- acptemplate/messageLog.tpl | 68 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/acptemplate/messageLog.tpl b/acptemplate/messageLog.tpl index 97c6341..d286e9d 100644 --- a/acptemplate/messageLog.tpl +++ b/acptemplate/messageLog.tpl @@ -1,5 +1,14 @@ {include file='header' pageTitle='chat.acp.log.title'} - + + + +

    {lang}{@$pageTitle}{/lang}

    @@ -44,33 +53,38 @@

    {lang}wcf.global.noItems{/lang}

    {/if} {else} -
    -
    -

    {lang}chat.acp.log.title{/lang} {#$messages|count}

    -
    +
    + - - - - - - - - - - - - {foreach from=$messages item='message'} - - - - - - - - {/foreach} - -
    {lang}wcf.global.objectID{/lang}{lang}chat.general.time{/lang}{lang}wcf.user.username{/lang}{lang}chat.acp.log.message{/lang}
    {$message->messageID}{$message->time|date:'H:i:s'}

    {@$message->getUserProfile()->getAvatar()->getImageTag(24)}

    {$message->username}{@$message->getFormattedMessage('text/simplified-html')}
    + {section name=contentLoop loop=24 step=3} +
    + + + {section name=subTabLoop loop=6} + {assign var=subAnchor value='timeTab-'|concat:$contentLoop|concat:'-subTab-'|concat:$subTabLoop} + + {/section} +
    + {/section}
    {/if} From cc73d896727ce38ed4d3349de08dbfe838ad723a Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 2 Aug 2013 19:38:13 +0200 Subject: [PATCH 06/13] Display messages in their appropriate tab. --- acptemplate/messageLog.tpl | 72 +++++++++++++++------- file/lib/acp/page/MessageLogPage.class.php | 25 ++++++-- 2 files changed, 70 insertions(+), 27 deletions(-) diff --git a/acptemplate/messageLog.tpl b/acptemplate/messageLog.tpl index d286e9d..0c893b2 100644 --- a/acptemplate/messageLog.tpl +++ b/acptemplate/messageLog.tpl @@ -57,33 +57,63 @@ {section name=contentLoop loop=24 step=3} -
    - - - {section name=subTabLoop loop=6} - {assign var=subAnchor value='timeTab-'|concat:$contentLoop|concat:'-subTab-'|concat:$subTabLoop} - - {/section} -
    + + {/if} + {/section} +
    + {/if} {/section} {/if} diff --git a/file/lib/acp/page/MessageLogPage.class.php b/file/lib/acp/page/MessageLogPage.class.php index ccfc254..4f60406 100644 --- a/file/lib/acp/page/MessageLogPage.class.php +++ b/file/lib/acp/page/MessageLogPage.class.php @@ -78,26 +78,39 @@ public function readData() { parent::readData(); try { - if($this->date > TIME_NOW) { + if ($this->date > TIME_NOW) { throw new \wcf\system\exception\UserInputException('date', 'inFuture'); } - } catch(\wcf\system\exception\UserInputException $e) { + } catch (\wcf\system\exception\UserInputException $e) { $this->errorField = $e->getField(); $this->errorType = $e->getType(); + return; } try { - if($this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { + if ($this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { throw new \wcf\system\exception\UserInputException('date', 'tooLongAgo'); } - } catch(\wcf\system\exception\UserInputException $e) { + } catch (\wcf\system\exception\UserInputException $e) { $this->errorField = $e->getField(); $this->errorType = $e->getType(); + return; } - $this->messages = \chat\data\message\ViewableMessageList::getMessagesBetween($this->room, $this->date, $this->date + 86399); + $messages = \chat\data\message\ViewableMessageList::getMessagesBetween($this->room, $this->date, $this->date + 86399); + + foreach ($messages as $message) { + $hour = ((int) date('H', $message->time)) * 2; + $minutes = (int) date('i', $message->time); + + if ($minutes >= 30) { + $hour += 1; + } + + $this->messages[$hour][] = $message; + } } /** @@ -108,7 +121,7 @@ public function readParameters() { $this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); - foreach($this->rooms as $id => $room) { + foreach ($this->rooms as $id => $room) { if (!$room->permanent) unset($this->rooms[$key]); } From 8c2d6efec0213004d0ea2623fdc9635f1ccae108 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 2 Aug 2013 19:59:57 +0200 Subject: [PATCH 07/13] Fix formatting I keep forgetting these rules ... --- file/lib/acp/page/MessageLogPage.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/file/lib/acp/page/MessageLogPage.class.php b/file/lib/acp/page/MessageLogPage.class.php index 4f60406..7cfc5a5 100644 --- a/file/lib/acp/page/MessageLogPage.class.php +++ b/file/lib/acp/page/MessageLogPage.class.php @@ -81,7 +81,8 @@ public function readData() { if ($this->date > TIME_NOW) { throw new \wcf\system\exception\UserInputException('date', 'inFuture'); } - } catch (\wcf\system\exception\UserInputException $e) { + } + catch (\wcf\system\exception\UserInputException $e) { $this->errorField = $e->getField(); $this->errorType = $e->getType(); @@ -92,7 +93,8 @@ public function readData() { if ($this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { throw new \wcf\system\exception\UserInputException('date', 'tooLongAgo'); } - } catch (\wcf\system\exception\UserInputException $e) { + } + catch (\wcf\system\exception\UserInputException $e) { $this->errorField = $e->getField(); $this->errorType = $e->getType(); From 74caf2c7ec8b90b17c482e3f832d43cf11065bad Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Thu, 5 Sep 2013 20:50:47 +0200 Subject: [PATCH 08/13] Implement Ajax-loading of message protocol --- acptemplate/__messageLogTable.tpl | 26 +++++ acptemplate/messageLog.tpl | 80 +++++--------- .../js/be.bastelstu.Chat.ACP.Log.litcoffee | 102 ++++++++++++++++++ file/lib/acp/page/MessageLogPage.class.php | 2 +- file/lib/data/message/MessageAction.class.php | 33 ++++++ 5 files changed, 190 insertions(+), 53 deletions(-) create mode 100644 acptemplate/__messageLogTable.tpl create mode 100644 file/acp/js/be.bastelstu.Chat.ACP.Log.litcoffee diff --git a/acptemplate/__messageLogTable.tpl b/acptemplate/__messageLogTable.tpl new file mode 100644 index 0000000..f12c738 --- /dev/null +++ b/acptemplate/__messageLogTable.tpl @@ -0,0 +1,26 @@ +{if $messages|count > 0} + + + + + + + + + + + + {foreach from=$messages item="message"} + + + + + + + + {/foreach} + +
    {lang}wcf.global.objectID{/lang}{lang}chat.general.time{/lang}{lang}wcf.user.username{/lang}{lang}chat.acp.log.message{/lang}
    {$message->messageID}{$message->time|date:"H:i:s"}

    {@$message->getUserProfile()->getAvatar()->getImageTag(24)}

    {$message->username}{@$message->getFormattedMessage("text/simplified-html")}
    +{else} +

    {lang}wcf.global.noItems{/lang}

    +{/if} diff --git a/acptemplate/messageLog.tpl b/acptemplate/messageLog.tpl index 0c893b2..abeb96b 100644 --- a/acptemplate/messageLog.tpl +++ b/acptemplate/messageLog.tpl @@ -1,8 +1,11 @@ {include file='header' pageTitle='chat.acp.log.title'} - + + - +{if $errorField === ''} + +{/if}
    @@ -51,11 +53,7 @@ -{if $messages|count == 0} - {if $errorField === ""} -

    {lang}wcf.global.noItems{/lang}

    - {/if} -{else} +{if $errorField === ''}
    + + {if $errorField === ''}