LAN_Portal/chat/README.md
2026-10-16 16:22:59 -04:00

11 lines
1.5 KiB
Markdown
Executable file

CHAT FEATURES
Chat is modular. To add a chat feature, create files in chat/features/ named after the feature. Every features/*.php is included, and every features/*.js and features/*.css is loaded, in filename order. Do not edit chat.php, chat-live.js or index.php unless I ask.
PHP: start with if (!defined('PORTAL')) { http_response_code(403); exit; }, then register callbacks with chat_on($hook, $fn). Hooks:
- before_send($msg): return the changed message array, or throw new Exception('reason') to reject.
- render_text($html, $msg): the escaped message text; return it changed. Never un-escape.
- msg_top($html, $msg) and msg_bottom($html, $msg): start with ''; return the string with HTML appended (above or below a message).
- form_extra() and below_chat(): echo HTML inside or after the send form.
Hooks that take $html return the new value, not echo it. Use chat_who() for a per-device id, chat_read() to read messages, and chat_update(function (&$msgs) { ... }) to change stored messages safely. To handle your own POST, check chat_action in the feature file; never use a field named "action".
JS: vanilla, one or two jobs per file, no libraries. The page is re-rendered by polling, so listen for the 'chat:updated' event on #chat instead of assuming the log is static. Messages are .chat-msg elements with data-id. Use Bootstrap classes and theme variables; no hard-coded colours, no remote assets.
Keep it simple, say what you did not test, and list any files you created.