Commit
This commit is contained in:
parent
00814c6fb7
commit
e1e9c9e99b
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB |
@ -27,35 +27,40 @@ Route::match('get|post','/willychat/', function() {
|
||||
$default_nick = 'Willy';
|
||||
$nick = $default_nick;
|
||||
$just_sent_message = false;
|
||||
$errmsg = false;
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$nick = filter_input(INPUT_POST, 'nick');
|
||||
$text = filter_input(INPUT_POST, 'text');
|
||||
|
||||
$errmsg = (function() use (&$text, &$nick): string|false {
|
||||
|
||||
if (empty(trim($nick, ' '))) {
|
||||
$nick = $default_nick;
|
||||
return 'You must choose a nickname.';
|
||||
}
|
||||
|
||||
if (strlen($nick) > 128) {
|
||||
view('pages/willychat/error', [
|
||||
'error' => 'Your nickname is too long.'
|
||||
]);
|
||||
die();
|
||||
$nick_max_chars = 128;
|
||||
if (strlen($nick) > $nick_max_chars) {
|
||||
return 'Your nickname is too long.';
|
||||
}
|
||||
|
||||
if (strlen($text) > 4096) {
|
||||
view('pages/willychat/error', [
|
||||
'error' => 'Do not send EXTREMELY long messages.'
|
||||
]);
|
||||
die();
|
||||
$text_max_chars = 4096;
|
||||
if (strlen($text) > $text_max_chars) {
|
||||
return 'Your message is too long. ' . strlen($text) . ' out of ' . $text_max_chars . ' characters.';
|
||||
}
|
||||
|
||||
if (empty(trim($text, ' '))) {
|
||||
return 'Message body cannot be empty.';
|
||||
}
|
||||
|
||||
return false;
|
||||
})();
|
||||
|
||||
if (!$errmsg) {
|
||||
if (count(WillyChat::$messages) > 10) {
|
||||
array_pop(WillyChat::$messages);
|
||||
}
|
||||
|
||||
if (!empty(trim($text, ' '))) {
|
||||
|
||||
array_unshift(WillyChat::$messages, [
|
||||
'nick' => $nick,
|
||||
'date' => time(),
|
||||
@ -68,13 +73,13 @@ Route::match('get|post','/willychat/', function() {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$just_sent_message = true;
|
||||
}
|
||||
|
||||
view('pages/willychat/index', [
|
||||
'nick' => $nick,
|
||||
'just_sent_message' => $just_sent_message,
|
||||
'errmsg' => $errmsg
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>What are you doing?</title>
|
||||
<link rel="stylesheet" href="<?=url('/static/style/fonts.css')?>">
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
#errordialog {
|
||||
background: tomato;
|
||||
color: white;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
padding: .75rem;
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
a {
|
||||
color: #0f0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="errordialog">
|
||||
|
||||
<h2><?=$error?></h2>
|
||||
|
||||
<a href="">I understand.</a>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -37,6 +37,7 @@
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
border: 0;
|
||||
text-indent: .5rem;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
@ -44,7 +45,7 @@
|
||||
width: 100%;
|
||||
}
|
||||
td {
|
||||
border: 1px solid #aaa;
|
||||
border: 1px solid silver;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -52,16 +53,20 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 15%;">
|
||||
<input style="text-indent: .5rem" type="text" name="nick" id="nick" placeholder="Nickname" value="<?=htmlspecialchars($nick)?>" autocomplete="off">
|
||||
<input type="text" name="nick" id="nick" placeholder="Nickname" value="<?=htmlspecialchars($nick)?>" autocomplete="off">
|
||||
</td>
|
||||
<td style="width: 75%">
|
||||
<input style="text-indent: .5rem" type="textarea" name="text" id="text" placeholder="Message" autocomplete="off">
|
||||
<input type="textarea" name="text" id="text" placeholder="Message" autocomplete="off">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input style="display: none;" type="submit" value="Send">
|
||||
</form>
|
||||
|
||||
<?php if ($errmsg): ?>
|
||||
<p style="color: red">Error: <?=$errmsg?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="messages">
|
||||
<iframe src="<?=url('/willychat/messages')?>" marginwidth="0" marginheight="0" scrolling="yes" frameborder="0"></iframe>
|
||||
</div>
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
<?php foreach($messages as $message): ?>
|
||||
<div>
|
||||
<small><?=gmdate("D M j G:i:s Y", $message['date']);?> <span style="color: yellow"><?=htmlspecialchars($message['nick'])?></span> says:</small>
|
||||
<small><span style="color: yellow"><?=htmlspecialchars($message['nick'])?></span> <?=gmdate("D M j G:i:s Y", $message['date']);?></small>
|
||||
<p><?=htmlspecialchars($message['text'])?></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
Loading…
Reference in New Issue
Block a user