Commit
This commit is contained in:
parent
0e3a2a3a9c
commit
8a0135ac54
BIN
public/static/img/tower.gif
Normal file
BIN
public/static/img/tower.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
@ -22,7 +22,7 @@ a {
|
||||
}
|
||||
|
||||
h1 {
|
||||
border-bottom: 4px double yellow;
|
||||
border-bottom: .25rem double yellow;
|
||||
color: yellow;
|
||||
}
|
||||
|
||||
@ -31,14 +31,14 @@ img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
code {
|
||||
display: block;
|
||||
max-width: min-content;
|
||||
margin: auto;
|
||||
font-family: monospace;
|
||||
background: black;
|
||||
color: greenyellow;
|
||||
padding: 8px;
|
||||
max-width: min-content;
|
||||
display: block;
|
||||
padding: .75rem;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
}
|
@ -9,6 +9,10 @@ ErrorHandler::register(function($error_messages) {
|
||||
|
||||
Route::get('/', fn() => view('pages/home'));
|
||||
|
||||
Route::group(function() {
|
||||
require __DIR__ . '/willychat.php';
|
||||
});
|
||||
|
||||
Route::get('/test/$whatever?', function($whatever = 'Default Value') {
|
||||
echo htmlspecialchars($whatever);
|
||||
});
|
||||
|
77
routes/willychat.php
Normal file
77
routes/willychat.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
use WillySoft\Http\Route;
|
||||
|
||||
abstract class WillyChat {
|
||||
public static string $data_path;
|
||||
public static array $messages;
|
||||
}
|
||||
|
||||
Route::middleware(function() {
|
||||
WillyChat::$data_path = '/dev/shm/database.json';
|
||||
|
||||
if (!file_exists(WillyChat::$data_path)) {
|
||||
file_put_contents(
|
||||
WillyChat::$data_path,
|
||||
json_encode([])
|
||||
);
|
||||
}
|
||||
|
||||
WillyChat::$messages = json_decode(
|
||||
file_get_contents(WillyChat::$data_path),
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
Route::match('get|post','/willychat/', function() {
|
||||
$default_nick = 'Willy';
|
||||
$nick = $default_nick;
|
||||
$just_sent_message = false;
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$nick = filter_input(INPUT_POST, 'nick');
|
||||
$text = filter_input(INPUT_POST, 'text');
|
||||
|
||||
if (empty(trim($nick, ' '))) {
|
||||
$nick = $default_nick;
|
||||
}
|
||||
|
||||
if (count(WillyChat::$messages) > 10) {
|
||||
array_pop(WillyChat::$messages);
|
||||
}
|
||||
|
||||
if (!empty(trim($text, ' '))) {
|
||||
|
||||
array_unshift(WillyChat::$messages, [
|
||||
'nick' => $nick,
|
||||
'date' => time(),
|
||||
'text' => $text
|
||||
]);
|
||||
|
||||
file_put_contents(WillyChat::$data_path,
|
||||
json_encode(
|
||||
WillyChat::$messages
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$just_sent_message = true;
|
||||
}
|
||||
|
||||
view('pages/willychat/index', [
|
||||
'nick' => $nick,
|
||||
'just_sent_message' => $just_sent_message
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/willychat/messages', function() {
|
||||
view('pages/willychat/messages', [
|
||||
'messages' => WillyChat::$messages
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/willychat/sync', function() {
|
||||
json_response(
|
||||
hash('crc32', serialize(WillyChat::$messages))
|
||||
);
|
||||
});
|
@ -40,8 +40,12 @@
|
||||
|
||||
<img src="<?=url('/static/img/15.gif')?>" alt="">
|
||||
|
||||
<p>Having a problem?</p>
|
||||
|
||||
<p>Send me a nice and positive message on matrix: <a href="https://matrix.to/#/@william:willy.club">@william:willy.club</a></p>
|
||||
|
||||
<p>We love you! xoxo</p>
|
||||
|
||||
<img src="<?=url('/static/img/lovebar.gif')?>" alt="">
|
||||
|
||||
<h1>Awesome webring</h1>
|
||||
|
75
views/pages/willychat/index.php
Normal file
75
views/pages/willychat/index.php
Normal file
@ -0,0 +1,75 @@
|
||||
<!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>WillyChat</title>
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
color: white;
|
||||
}
|
||||
body .messages {
|
||||
flex: 1 1 auto;
|
||||
display: flex;
|
||||
}
|
||||
.messages {
|
||||
border: 0;
|
||||
}
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
input {
|
||||
color: #fff;
|
||||
width: 100%;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
padding: .75rem;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
border: 0;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin-bottom: .75rem;;
|
||||
width: 100%;
|
||||
}
|
||||
td {
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 15%;">
|
||||
<input style="text-indent: .5rem" 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">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input style="display: none;" type="submit" value="Send">
|
||||
</form>
|
||||
|
||||
<div class="messages">
|
||||
<iframe src="<?=url('/willychat/messages')?>" marginwidth="0" marginheight="0" scrolling="yes" frameborder="0"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
if (<?=$just_sent_message ? 'true' : 'false'?>) {
|
||||
text.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
46
views/pages/willychat/messages.php
Normal file
46
views/pages/willychat/messages.php
Normal file
@ -0,0 +1,46 @@
|
||||
<!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">
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
div {
|
||||
border: 1px solid silver;
|
||||
margin-bottom: 8px;
|
||||
padding: 8px;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
color: white;
|
||||
}
|
||||
div > small {
|
||||
color: gray;
|
||||
}
|
||||
div > p {
|
||||
margin: 0;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php foreach($messages as $message): ?>
|
||||
<div>
|
||||
<small><?=gmdate("D M j G:i:s Y", $message['date']);?> <?=htmlspecialchars($message['nick'])?> says:</small>
|
||||
<p><?=htmlspecialchars($message['text'])?></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<script>
|
||||
let hash = '';
|
||||
setInterval(async () => {
|
||||
let new_hash = await fetch('sync').then((response) => response.json());
|
||||
if (hash == '') {
|
||||
hash = new_hash;
|
||||
}
|
||||
if (new_hash !== hash) {
|
||||
document.location.reload();
|
||||
}
|
||||
}, 2000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,12 +1,25 @@
|
||||
</main>
|
||||
|
||||
<h1>Live chat</h1>
|
||||
<img src="<?=url('/static/img/under-construction-small.gif')?>" alt="">
|
||||
<hr>
|
||||
<h1 id="message-board">Message board</h1>
|
||||
<img src="<?=url('/static/img/tower.gif')?>" alt="">
|
||||
<p>Racism <s>not</s> allowed</p>
|
||||
<style>
|
||||
.willychat {
|
||||
max-width: 30rem;
|
||||
max-height: 40rem;
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<iframe class="willychat" src="<?=url('/willychat/')?>" frameborder="0" scrolling="no"></iframe>
|
||||
|
||||
<hr>
|
||||
<br>
|
||||
<br>
|
||||
<img src="<?=url('/static/img/3d-spinning-toilet-smiley-emoticon-small.gif')?>" alt="the Willy Club(WC)">
|
||||
<br>
|
||||
<small>Copyeverything © 2020 - 2194</small>
|
||||
<small>Copyeverything © 2020 - <?=date('Y')?></small>
|
||||
</body>
|
||||
</html>
|
@ -14,6 +14,7 @@ function special_events(): string {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?=htmlspecialchars($title)?> - the Willy Club</title>
|
||||
<link rel="stylesheet" href="<?=url('/static/style/main.css')?>">
|
||||
<link rel="shortcut icon" href="<?=url('/static/img/3d-spinning-toilet-smiley-emoticon-small.gif')?>" type="image/x-icon">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user