First git commit

This commit is contained in:
root
2026-09-08 18:21:10 +01:00
commit 66911dc450
65 changed files with 7012 additions and 0 deletions

50
public_html/compose.php Normal file
View File

@ -0,0 +1,50 @@
<?php
require_once __DIR__ . '/lib/bootstrap.php';
$me = require_login();
$toId = (int)($_GET['to'] ?? 0);
$reId = (int)($_GET['re'] ?? 0);
$toName = '';
$subj = '';
if ($toId) { $t = user_by_id($toId); if ($t) $toName = $t['username']; }
if ($reId) {
$s = db()->prepare("SELECT subject FROM messages WHERE id=? AND to_id=?");
$s->execute([$reId, $me['id']]);
$sub = $s->fetchColumn();
if ($sub) $subj = (strncasecmp($sub, 'Re:', 3) === 0) ? $sub : 'Re: ' . $sub;
}
$err = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_csrf();
$toName = trim((string)($_POST['to'] ?? ''));
$subj = mb_substr(trim((string)($_POST['subject'] ?? '')), 0, 60);
$body = trim((string)($_POST['body'] ?? ''));
$dest = user_by_name($toName);
if (!$dest) $err = 'No such user: ' . $toName;
elseif ((int)$dest['id'] === (int)$me['id']) $err = 'You cannot message yourself.';
elseif ($subj === '') $err = 'Subject required.';
elseif ($body === '') $err = 'Message body required.';
else {
db()->prepare("INSERT INTO messages (from_id,to_id,subject,body,created_at)
VALUES (?,?,?,?,?)")
->execute([$me['id'], $dest['id'], $subj, mb_substr($body, 0, 4000), time()]);
page_start('Sent', ['back' => '/inbox.php']);
p_ok('Message sent to ' . $dest['username'] . '.');
p_links([['/inbox.php', 'Inbox'], ['/index.php', 'Home']]);
page_end();
exit;
}
}
page_start('New message', ['back' => '/inbox.php']);
if ($err) p_err($err);
p_form('/compose.php', [
['name' => 'to', 'label' => 'To (username)', 'value' => $toName, 'maxlength' => 16],
['name' => 'subject', 'label' => 'Subject', 'value' => $subj, 'maxlength' => 60],
['name' => 'body', 'label' => 'Message', 'type' => is_wml() ? 'text' : 'textarea',
'maxlength' => is_wml() ? 200 : 4000],
], 'Send');
p_links([['/inbox.php', 'Inbox'], ['/users.php', 'Member list']]);
page_end();