diff --git a/chat/chat.php b/chat/chat.php deleted file mode 100644 index 2f04ccf..0000000 --- a/chat/chat.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @copyright Copyright (C) 2018-2025, Frédéric Tempez - * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International - * @link http://zwiicms.fr/ - */ - -class chat extends common -{ - const VERSION = '0.1'; - const REALNAME = 'Chat'; - const DELETE = true; - const UPDATE = '0.0'; - const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json) - - public static $actions = [ - //'add' => self::GROUP_MODERATOR, - //'config' => self::GROUP_MODERATOR, - //'edit' => self::GROUP_MODERATOR, - 'index' => self::GROUP_VISITOR, - 'getFormattedMessages' => self::GROUP_VISITOR, - ]; - - public static $messages = []; - - public function index(): void - { - - if ($this->isPost()) { - - $message = filter_input(INPUT_POST, 'message'); - - if ($message) { - $timestamp = time(); - $userId = $this->getUser('id'); - - $chatData = $this->getData(['module', $this->getUrl(2), 'chat']) ?? []; - $chatData[$timestamp] = [ - 'user_id' => $userId, - 'message' => $message - ]; - - $this->setData(['module', $this->getUrl(2), 'chat'], $chatData); - - if ( - isset($_SERVER['HTTP_X_REQUESTED_WITH']) && - strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest' - ) { - echo json_encode(['success' => true]); - exit; - } - } - } - - self::$messages = $this->getFormattedMessages(); - - // Valeurs en sortie - $this->addOutput([ - 'title' => 'ChatRoom', - 'view' => 'index' - ]); - } - - private function getFormattedMessages() - { - $chatData = $this->getData(['module', $this->getUrl(2), 'chat']) ?? []; - $messages = []; - - krsort($chatData); - - foreach ($chatData as $timestamp => $data) { - $messages[] = [ - 'timestamp' => $timestamp, - 'user_id' => $data['user_id'], - 'username' => $this->getUser('id'), - 'message' => $data['message'] - ]; - } - - return $messages; - } -} diff --git a/chat/view/index/index.css b/chat/view/index/index.css deleted file mode 100644 index 6c32448..0000000 --- a/chat/view/index/index.css +++ /dev/null @@ -1,55 +0,0 @@ -.chat-container { - max-width: 800px; - margin: 0 auto; -} - -.chat-messages { - height: 400px; - overflow-y: auto; - border: 1px solid #ccc; - padding: 10px; - margin-bottom: 10px; -} - -.message { - margin-bottom: 10px; - padding: 5px; - background: #f5f5f5; - border-radius: 4px; -} - -.username { - font-weight: bold; - margin-right: 10px; - color: #2c5282; -} - -.timestamp { - color: #666; - font-size: 0.8em; -} - -.chat-form { - display: flex; - gap: 10px; -} - -#messageInput { - flex: 1; - padding: 8px; - border: 1px solid #ccc; - border-radius: 4px; -} - -button { - padding: 8px 16px; - background: #4299e1; - color: white; - border: none; - border-radius: 4px; - cursor: pointer; -} - -button:hover { - background: #2b6cb0; -} \ No newline at end of file diff --git a/chat/view/index/index.js.php b/chat/view/index/index.js.php deleted file mode 100644 index 0f104df..0000000 --- a/chat/view/index/index.js.php +++ /dev/null @@ -1,37 +0,0 @@ -document.getElementById('chatForm').addEventListener('submit', function (e) { - e.preventDefault(); - - const messageInput = document.getElementById('messageInput'); - const message = messageInput.value; - - fetch(window.location.href, { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'X-Requested-With': 'XMLHttpRequest' - }, - body: 'message=' + encodeURIComponent(message) - }) - .then(response => response.json()) - .then(data => { - if (data.success) { - messageInput.value = ''; - location.reload(); // Option simple - vous pourriez préférer une mise à jour AJAX plus sophistiquée - } - }); -}); - -// Fonction optionnelle pour actualiser automatiquement le chat -function refreshChat() { - fetch(window.location.href) - .then(response => response.text()) - .then(html => { - const parser = new DOMParser(); - const doc = parser.parseFromString(html, 'text/html'); - const newMessages = doc.querySelector('#chatMessages').innerHTML; - document.getElementById('chatMessages').innerHTML = newMessages; - }); -} - -// Décommentez pour activer l'actualisation automatique -// setInterval(refreshChat, 10000); // Actualise toutes les 10 secondes \ No newline at end of file diff --git a/chat/view/index/index.php b/chat/view/index/index.php deleted file mode 100644 index 7e8dfeb..0000000 --- a/chat/view/index/index.php +++ /dev/null @@ -1,18 +0,0 @@ -
Cet item ne reçoit pas de commentaire.