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
2015-04-11 21:34:49 +02:00

29 lines
No EOL
671 B
PHP

<?php
$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;
if (!ctype_digit($pos) || !file_exists($file)) return;
settype($pos, "integer");
settype($lastdate, "integer");
$data = array();
if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) {
$pos=0;
} else {
$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));
?>