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

33 lines
796 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'] : '';
2015-04-17 09:09:51 +02:00
$time = time();
$date = date('Y-m-d', $time);
2015-04-11 19:32:50 +02:00
$file = './history/'.$room.$date;
2015-04-06 17:46:57 +02:00
2015-04-17 09:09:51 +02:00
if (!ctype_digit($pos)) 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-06 17:46:57 +02:00
$data = array();
2015-04-17 09:09:51 +02:00
if (file_exists($file)) {
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);
}
2015-04-11 21:34:49 +02:00
}
2015-04-17 09:09:51 +02:00
} else if ($date!=date('Y-m-d',$lastdate)) {
$data[0]=array($time,"","");
2015-04-06 17:46:57 +02:00
}
2015-04-11 21:34:49 +02:00
echo json_encode(array('pos' => $pos, 'data' => $data));
2015-04-06 17:46:57 +02:00
2015-04-11 19:32:50 +02:00
?>