1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Fix clock shift issue in MessageLogDownloadPage

This commit is contained in:
Tim Düsterhus 2014-10-31 02:01:32 +01:00
parent dad63c7967
commit 79196bade9

View File

@ -43,9 +43,9 @@ class MessageLogDownloadPage extends \wcf\page\AbstractPage {
/** /**
* given date * given date
* *
* @var integer * @var \DateTime
*/ */
public $date = 0; public $date = null;
/** /**
* active room * active room
@ -69,11 +69,13 @@ class MessageLogDownloadPage extends \wcf\page\AbstractPage {
public function readData() { public function readData() {
parent::readData(); parent::readData();
if ($this->date > TIME_NOW) { $now = new \DateTime('now', WCF::getUser()->getTimeZone());
if ($this->date->getTimestamp() > $now->getTimestamp()) {
throw new \wcf\system\exception\IllegalLinkException(); throw new \wcf\system\exception\IllegalLinkException();
} }
if (CHAT_LOG_ARCHIVETIME !== -1 && $this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { $oldest = new \DateTime('today -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day', WCF::getUser()->getTimeZone());
if (CHAT_LOG_ARCHIVETIME !== -1 && $this->date->getTimestamp() < $oldest->getTimestamp()) {
throw new \wcf\system\exception\IllegalLinkException(); throw new \wcf\system\exception\IllegalLinkException();
} }
@ -85,7 +87,7 @@ public function readData() {
$file = new \wcf\system\io\File($this->tmpFile); $file = new \wcf\system\io\File($this->tmpFile);
$file->write(WCF::getLanguage()->get('chat.acp.log.title') . ': ' . (string) $this->room . "\n"); $file->write(WCF::getLanguage()->get('chat.acp.log.title') . ': ' . (string) $this->room . "\n");
for ($start = $this->date, $end = $start + 86399; $start < $end; $start += 1800) { for ($start = $this->date->getTimestamp(), $end = $this->date->add(\DateInterval::createFromDateString('1day'))->sub(\DateInterval::createFromDateString('1second'))->getTimestamp(); $start < $end; $start += 1800) {
$file->write(WCF::getTpl()->fetch('messageLogDownload', 'chat', array('messages' => \chat\data\message\MessageList::getMessagesBetween($this->room, $start, $start + 1799)))); $file->write(WCF::getTpl()->fetch('messageLogDownload', 'chat', array('messages' => \chat\data\message\MessageList::getMessagesBetween($this->room, $start, $start + 1799))));
} }
@ -117,8 +119,12 @@ public function readParameters() {
if (isset($_REQUEST['date'])) $date = $_REQUEST['date'].' 00:00:00'; if (isset($_REQUEST['date'])) $date = $_REQUEST['date'].' 00:00:00';
else $date = 'today 00:00:00'; else $date = 'today 00:00:00';
$this->date = @strtotime($date); try {
if ($this->date === false) throw new \wcf\system\exception\IllegalLinkException(); $this->date = new \DateTime($date, WCF::getUser()->getTimeZone());
}
catch (\Exception $e) {
throw new \wcf\system\exception\IllegalLinkException();
}
} }
/** /**
@ -127,9 +133,7 @@ public function readParameters() {
public function show() { public function show() {
parent::show(); parent::show();
$dateTime = \wcf\util\DateUtil::getDateTimeByTimestamp($this->date); $fileReader = new \wcf\util\FileReader($this->tmpFile, array('mimeType' => 'text/plain', 'filename' => str_replace(' ', '-', WCF::getLanguage()->get('chat.acp.log.title') . ' ' . $this->room.'-'.\wcf\util\DateUtil::format($this->date, 'Y-m-d').'.txt')));
$fileReader = new \wcf\util\FileReader($this->tmpFile, array('mimeType' => 'text/plain', 'filename' => str_replace(' ', '-', WCF::getLanguage()->get('chat.acp.log.title') . ' ' . $this->room.'-'.\wcf\util\DateUtil::format($dateTime, 'Y-m-d').'.txt')));
$fileReader->send(); $fileReader->send();
exit; exit;