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/post.php

30 lines
649 B
PHP
Raw Normal View History

2015-04-06 17:46:57 +02:00
<?php
$text = isset($_POST['text']) ? $_POST['text'] : '';
2015-04-10 23:54:09 +02:00
$name = isset($_POST['name']) ? $_POST['name'] : '';
$room = isset($_POST['room']) ? $_POST['room'] : '';
2015-04-06 17:46:57 +02:00
2015-04-11 19:32:50 +02:00
if ($text === '' || $name === '' ) return;
2015-04-06 17:46:57 +02:00
$time = time();
$date = date('Y-m-d', $time);
$historyDir = './history/';
2015-04-10 23:54:09 +02:00
$historyFile = $historyDir.$room.$date;
2015-04-06 17:46:57 +02:00
$fh = @fopen($historyFile, 'a');
if ($fh === false) {
mkdir($historyDir);
$fh = @fopen($historyFile, 'a');
}
/* start semafore */
flock($fh, LOCK_EX);
2015-04-11 19:32:50 +02:00
$data = array($time, $name, stripslashes(htmlspecialchars($text)));
2015-04-10 23:54:09 +02:00
fwrite($fh, implode('>', $data)."\n");
2015-04-06 17:46:57 +02:00
/* end semafore */
flock($fh, LOCK_UN);
fclose($fh);