2013-07-28 21:27:28 +00:00
|
|
|
<?php
|
|
|
|
namespace chat\acp\page;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists chat log.
|
|
|
|
*
|
|
|
|
* @author Maximilian Mader
|
|
|
|
* @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 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(
|
2013-09-06 14:16:55 +00:00
|
|
|
'admin.chat.canReadLog'
|
2013-07-28 21:27:28 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
2013-08-02 17:38:13 +00:00
|
|
|
if ($this->date > TIME_NOW) {
|
2013-07-28 21:27:28 +00:00
|
|
|
throw new \wcf\system\exception\UserInputException('date', 'inFuture');
|
|
|
|
}
|
2013-08-02 17:59:57 +00:00
|
|
|
}
|
|
|
|
catch (\wcf\system\exception\UserInputException $e) {
|
2013-07-28 21:27:28 +00:00
|
|
|
$this->errorField = $e->getField();
|
|
|
|
$this->errorType = $e->getType();
|
2013-08-02 17:38:13 +00:00
|
|
|
|
2013-07-28 21:27:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2013-08-02 17:38:13 +00:00
|
|
|
if ($this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) {
|
2013-07-28 21:27:28 +00:00
|
|
|
throw new \wcf\system\exception\UserInputException('date', 'tooLongAgo');
|
|
|
|
}
|
2013-08-02 17:59:57 +00:00
|
|
|
}
|
|
|
|
catch (\wcf\system\exception\UserInputException $e) {
|
2013-07-28 21:27:28 +00:00
|
|
|
$this->errorField = $e->getField();
|
|
|
|
$this->errorType = $e->getType();
|
2013-08-02 17:38:13 +00:00
|
|
|
|
2013-07-28 21:27:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-05 18:50:47 +00:00
|
|
|
$messages = \chat\data\message\ViewableMessageList::getMessagesBetween($this->room, $this->date, $this->date + 1799);
|
2013-08-02 17:38:13 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-07-28 21:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
|
|
|
|
|
|
|
$this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
|
|
|
|
2013-08-02 17:38:13 +00:00
|
|
|
foreach ($this->rooms as $id => $room) {
|
2013-09-08 18:54:44 +00:00
|
|
|
if (!$room->permanent) unset($this->rooms[$id]);
|
2013-07-28 21:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2013-09-08 18:52:31 +00:00
|
|
|
if (!$this->room->permanent) throw new \wcf\system\exception\PermissionDeniedException();
|
|
|
|
|
2013-07-28 21:27:28 +00:00
|
|
|
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
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|