1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minchat_ynh.git synced 2024-09-03 19:36:29 +02:00
minchat_ynh/sources/server.php

26 lines
633 B
PHP
Raw Normal View History

2015-04-06 17:46:57 +02:00
<?php
2015-04-11 19:32:50 +02:00
$pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : '';
$lastdate = isset($_REQUEST['lastdate']) ? $_REQUEST['lastdate'] : '';
$room = isset($_REQUEST['room']) ? $_REQUEST['room'] : '';
$date = date('Y-m-d');
$file = './history/'.$room.$date;
2015-04-06 17:46:57 +02:00
2015-04-11 19:32:50 +02:00
if (!ctype_digit($pos) || !file_exists($file)) return;
2015-04-06 17:46:57 +02:00
2015-04-11 19:32:50 +02:00
settype($pos, "integer");
settype($lastdate, "integer");
2015-04-10 23:54:09 +02:00
2015-04-11 19:32:50 +02:00
if ($date!=date('Y-m-d',$lastdate)) $pos=0;
2015-04-10 23:54:09 +02:00
2015-04-06 17:46:57 +02:00
$data = array();
2015-04-11 19:32:50 +02:00
$fh =fopen($file, "r");
if (fseek($fh, $pos)==0) {
$i=0;
while($lig=fgets($fh)){ $data[$i++] = explode('>', $lig); }
$pos =ftell($fh);
echo json_encode(array('pos' => $pos, 'data' => $data));
2015-04-06 17:46:57 +02:00
}
2015-04-11 19:32:50 +02:00
?>