From ed9d7f1511e450b0b94acf533562b170b7f31f98 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 12 Feb 2023 19:15:30 +0100 Subject: [PATCH] Remove chat cuz y'all can't behave! --- app/App/Controller/ChatController.php | 69 ----------------------- app/App/Model/ChatModel.php | 50 ----------------- config/default.config.php | 2 +- routes/start.php | 11 ---- views/pages/chat/index.php | 81 --------------------------- views/pages/chat/messages.php | 68 ---------------------- views/templates/footer.php | 16 ------ 7 files changed, 1 insertion(+), 296 deletions(-) delete mode 100644 app/App/Controller/ChatController.php delete mode 100644 app/App/Model/ChatModel.php delete mode 100644 views/pages/chat/index.php delete mode 100644 views/pages/chat/messages.php diff --git a/app/App/Controller/ChatController.php b/app/App/Controller/ChatController.php deleted file mode 100644 index 6097ffb..0000000 --- a/app/App/Controller/ChatController.php +++ /dev/null @@ -1,69 +0,0 @@ - 'Willy', - 'just_sent_message' => false, - 'errmsg' => false - ]); - } - - $nick = filter_input(INPUT_POST, 'nick'); - $text = filter_input(INPUT_POST, 'text'); - $errmsg = (function() use (&$text, &$nick): string { - if (empty(trim($nick, ' '))) { - return 'You must choose a nickname.'; - } - - $nick_max_chars = 128; - if (strlen($nick) > $nick_max_chars) { - return 'Your nickname is TOO LONG! ' . strlen($nick) . ' out of ' . $nick_max_chars. ' characters.'; - } - - $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 ''; - })(); - - if (empty($errmsg)) { - ChatModel::save_message( - $nick, - $text - ); - } - - view('pages/chat/index', [ - 'nick' => $nick, - 'just_sent_message' => true, - 'errmsg' => $errmsg - ]); - } - - static function messages() - { - view('pages/chat/messages', - ['messages' => ChatModel::get_messages()]); - } - - static function sync() - { - json_response(hash('crc32', serialize( - ChatModel::get_messages() - ))); - } -} \ No newline at end of file diff --git a/app/App/Model/ChatModel.php b/app/App/Model/ChatModel.php deleted file mode 100644 index 3a13f00..0000000 --- a/app/App/Model/ChatModel.php +++ /dev/null @@ -1,50 +0,0 @@ - 100) { - array_pop($messages); - } - - array_unshift(self::$messages, [ - 'nick' => $nick, - 'date' => time(), - 'text' => $text - ]); - - file_put_contents(Config::get('path_to_chat_json_file'), - json_encode( - self::$messages - ) - ); - } -} \ No newline at end of file diff --git a/config/default.config.php b/config/default.config.php index 0b604c7..e2b5c14 100644 --- a/config/default.config.php +++ b/config/default.config.php @@ -4,5 +4,5 @@ * Copy and name it config.php to override these defaults. */ return [ - 'path_to_chat_json_file' => '/dev/shm/database.json' + // nothing here yet! ]; \ No newline at end of file diff --git a/routes/start.php b/routes/start.php index 2ea0e91..c0f2edf 100644 --- a/routes/start.php +++ b/routes/start.php @@ -24,16 +24,5 @@ App::get('/echo/$text?', App::get('/error', DefaultController::error(...)); -use App\Controller\ChatController; - -App::group('/chat', function() { - App::form('/', - ChatController::index(...)); - App::get('/messages', - ChatController::messages(...)); - App::get('/sync', - ChatController::sync(...)); -}); - http_response_code(404); view('errors/404'); \ No newline at end of file diff --git a/views/pages/chat/index.php b/views/pages/chat/index.php deleted file mode 100644 index 0cd82d2..0000000 --- a/views/pages/chat/index.php +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - WillyChat - - - - -
- - - - - -
- - - -
- -
- - -

Error:

- - -
- -
- - - - - \ No newline at end of file diff --git a/views/pages/chat/messages.php b/views/pages/chat/messages.php deleted file mode 100644 index 428a5ba..0000000 --- a/views/pages/chat/messages.php +++ /dev/null @@ -1,68 +0,0 @@ - 'year', - 2592000 => 'month', - 604800 => 'week', - 86400 => 'day', - 3600 => 'hour', - 60 => 'minute', - 1 => 'second' - ); - foreach ($tokens as $unit => $text) { - if ($time < $unit) continue; - $numberOfUnits = floor($time / $unit); - return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); - } -} -?> - - - - - - - - - - - - -
- -

-
- - - - - \ No newline at end of file diff --git a/views/templates/footer.php b/views/templates/footer.php index 6787fc3..65daaaa 100644 --- a/views/templates/footer.php +++ b/views/templates/footer.php @@ -1,22 +1,6 @@
-

Message board

- -

Remember, be kind to each other

- - - -
-

the Willy Club(WC)