2015-04-06 17:46:57 +02:00
|
|
|
<?php
|
|
|
|
function v($v, $czyscHtmlIExit = false) {
|
|
|
|
if ($czyscHtmlIExit) ob_end_clean();
|
|
|
|
echo '<pre>' . print_r($v, true) . '</pre>';
|
|
|
|
if ($czyscHtmlIExit) exit;
|
|
|
|
}
|
|
|
|
function vv($v, $czyscHtmlIExit = false) {
|
|
|
|
if ($czyscHtmlIExit) ob_end_clean();
|
|
|
|
echo '<pre>';
|
|
|
|
var_dump($v);
|
|
|
|
echo '</pre>';
|
|
|
|
if ($czyscHtmlIExit) exit;
|
|
|
|
}
|
|
|
|
function vvv($var, & $result = null, $is_view = true)
|
|
|
|
{
|
|
|
|
if (is_array($var) || is_object($var)) foreach ($var as $key=> $value) vvv($value, $result[$key], false);
|
|
|
|
else $result = $var;
|
|
|
|
|
|
|
|
if ($is_view) v($result);
|
|
|
|
}
|
|
|
|
|
2015-04-10 23:54:09 +02:00
|
|
|
function getarr($arr,$key,$default) {
|
|
|
|
return isset($arr[$key]) ? $arr[$key] : $default;
|
2015-04-06 17:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteOldHistory() {
|
2015-04-10 23:54:09 +02:00
|
|
|
$expireDate = date('Y-m-d', strtotime("-1 day"));
|
2015-04-06 17:46:57 +02:00
|
|
|
foreach (glob('./history/*') as $f) {
|
2015-04-10 23:54:09 +02:00
|
|
|
if (substr(basename($f),-10) < $expireDate) {
|
2015-04-06 17:46:57 +02:00
|
|
|
unlink($f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------
|
2015-04-10 23:54:09 +02:00
|
|
|
// init setup.ini parms
|
|
|
|
$ini = parse_ini_file('conf/setup.ini');
|
|
|
|
$interval= getarr($ini,'interval',2500);
|
|
|
|
$delay= $interval+getarr($ini,'cache',60000);
|
|
|
|
$auth= explode(',',getarr($ini,'auth',''));
|
2015-04-06 17:46:57 +02:00
|
|
|
|
2015-04-10 23:54:09 +02:00
|
|
|
// read args
|
|
|
|
$name="";
|
2015-04-06 17:46:57 +02:00
|
|
|
if (isset($_REQUEST['name'])) {
|
2015-04-10 23:54:09 +02:00
|
|
|
$name = stripslashes(htmlspecialchars($_REQUEST['name']));
|
2015-04-06 17:46:57 +02:00
|
|
|
}
|
2015-04-10 23:54:09 +02:00
|
|
|
$room="";
|
2015-04-06 17:46:57 +02:00
|
|
|
if (isset($_REQUEST['room'])) {
|
2015-04-10 23:54:09 +02:00
|
|
|
$room = stripslashes(htmlspecialchars($_REQUEST['room']));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check args
|
|
|
|
if ($name.$room=="") {
|
|
|
|
// no args
|
|
|
|
$prompt = "Please fill in the form to continue:";
|
2015-04-06 17:46:57 +02:00
|
|
|
} else {
|
2015-04-10 23:54:09 +02:00
|
|
|
if ($name=="") {$prompt = "<em>User name missing.</em>";}
|
|
|
|
else if ($room=="") {$prompt="<em>Room missing.</em>";}
|
|
|
|
else if (in_array($name.":".$room,$auth)) {$prompt="";}
|
|
|
|
else if (in_array(":".$room,$auth)) {$prompt="";}
|
|
|
|
else if (in_array($name.":",$auth)) {$prompt="";}
|
|
|
|
else {$prompt="<em>User not authorized to this room.</em>";}
|
2015-04-06 17:46:57 +02:00
|
|
|
}
|
2015-04-10 23:54:09 +02:00
|
|
|
|
2015-04-06 17:46:57 +02:00
|
|
|
?>
|
2015-04-10 23:54:09 +02:00
|
|
|
<!DOCTYPE html>
|
2015-04-06 17:46:57 +02:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
2015-04-10 23:54:09 +02:00
|
|
|
<title>Minchat - <?php echo $room; ?> room</title>
|
2015-04-06 17:46:57 +02:00
|
|
|
<link type="text/css" rel="stylesheet" href="style.css" />
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<?php
|
2015-04-10 23:54:09 +02:00
|
|
|
if ($prompt!="") {
|
|
|
|
// Form to get args
|
|
|
|
echo'<div id="loginform"><p>';
|
|
|
|
echo $err;
|
|
|
|
echo $prompt;
|
|
|
|
echo '</p><form action="" method="get" class="tform"><p><label for="name">Name:</label><input type="text" name="name" id="name" value="';
|
|
|
|
echo $name;
|
|
|
|
echo '"/></p>';
|
|
|
|
echo '<p><label for="room">Room:</label><input type="text" name="room" id="room" value="';
|
|
|
|
echo $room;
|
|
|
|
echo '"/></p>';
|
|
|
|
echo '<br/><input type="submit" value="Enter" /></p></form></div>';
|
2015-04-06 17:46:57 +02:00
|
|
|
} else {
|
2015-04-10 23:54:09 +02:00
|
|
|
deleteOldHistory();
|
|
|
|
// Enter the room
|
2015-04-06 17:46:57 +02:00
|
|
|
?>
|
|
|
|
<div id="wrapper">
|
|
|
|
<div id="menu">
|
2015-04-10 23:54:09 +02:00
|
|
|
<p class="welcome">Welcome to the <b><?php echo $room; ?></b> room, <b><?php echo $name; ?></b></p>
|
2015-04-06 17:46:57 +02:00
|
|
|
<div style="clear:both"></div>
|
|
|
|
</div>
|
2015-04-10 23:54:09 +02:00
|
|
|
<div id="chatbox"></div>
|
2015-04-06 17:46:57 +02:00
|
|
|
<form name="message" action="">
|
|
|
|
<input name="usermsg" type="text" id="usermsg" size="63" autocomplete="off" autofocus/>
|
|
|
|
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<script type="text/javascript" src="lib/jquery-2.1.3.min.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
// jQuery Document
|
|
|
|
$(document).ready(function() {
|
|
|
|
var id = 'undefined';
|
|
|
|
//If user submits the form
|
|
|
|
$("#submitmsg").click(function() {
|
|
|
|
var clientmsg = $("#usermsg").val();
|
|
|
|
$("#usermsg").val('');
|
|
|
|
$("#usermsg").focus();
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: 'post.php',
|
2015-04-10 23:54:09 +02:00
|
|
|
data: {text: clientmsg,name:'<?php echo $name; ?>',room:'<?php echo $room; ?>',delay:'<?php echo $delay; ?>'},
|
2015-04-06 17:46:57 +02:00
|
|
|
//cache: false,
|
|
|
|
async: false,
|
|
|
|
success: function(data) {
|
|
|
|
loadLog();
|
|
|
|
},
|
|
|
|
error: function(request, status, error) {
|
|
|
|
$("#usermsg").val(clientmsg);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Load the file containing the chat log
|
|
|
|
function loadLog() {
|
|
|
|
var oldscrollHeight = $("#chatbox")[0].scrollHeight;
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: 'server.php',
|
2015-04-10 23:54:09 +02:00
|
|
|
data: {id: id,room:'<?php echo $room; ?>'},
|
2015-04-06 17:46:57 +02:00
|
|
|
dataType: 'json',
|
|
|
|
//cache: false,
|
|
|
|
async: false,
|
|
|
|
success: function(data) {
|
|
|
|
id = data.id;
|
|
|
|
var html = '';
|
|
|
|
var date;
|
|
|
|
for (var k in data.data.reverse()) {
|
|
|
|
date = new Date(parseInt(data.data[k][0])*1000);
|
|
|
|
date = date.toLocaleTimeString();
|
|
|
|
date = date.replace(/([\d]+\D+[\d]{2})\D+[\d]{2}(.*)/, '$1$2');
|
|
|
|
html = html
|
|
|
|
+"<div class='msgln'>("+date+") <b>"
|
|
|
|
+data.data[k][1]+"</b>: "+data.data[k][2]+"<br></div>";
|
|
|
|
}
|
|
|
|
$("#chatbox").append(html); //Insert chat messages into the #chatbox div
|
|
|
|
var newscrollHeight = $("#chatbox")[0].scrollHeight;
|
|
|
|
if (newscrollHeight > oldscrollHeight) {
|
|
|
|
$("#chatbox").scrollTop($("#chatbox")[0].scrollHeight);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
loadLog();
|
2015-04-10 23:54:09 +02:00
|
|
|
setInterval(loadLog, <?php echo $interval ?>); //Reload file every $interval ms
|
2015-04-06 17:46:57 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
2015-04-10 23:54:09 +02:00
|
|
|
<?php } ?>
|
2015-04-06 17:46:57 +02:00
|
|
|
</body>
|
|
|
|
</html>
|