= htmlspecialchars($t['title'], ENT_QUOTES) ?>
= nl2br(htmlspecialchars(substr($t['body'], 0, 200), ENT_QUOTES)) ?>= strlen($t['body']) > 200 ? '…' : '' ?>
pdo();
$userId = $_SESSION['user_id'] ?? null;
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'thread_create') {
if (!$userId) {
$error = 'Bitte einloggen, um Fragen zu stellen.';
} elseif ($pdo) {
$title = trim((string)($_POST['title'] ?? ''));
$body = trim((string)($_POST['body'] ?? ''));
if ($title === '' || $body === '') {
$error = 'Titel und Text sind erforderlich.';
} else {
$pdo->prepare('CREATE TABLE IF NOT EXISTS forum_threads (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
title VARCHAR(200) NOT NULL,
body TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci')->execute();
$pdo->prepare('INSERT INTO forum_threads (user_id, title, body) VALUES (:uid, :title, :body)')
->execute(['uid' => $userId, 'title' => $title, 'body' => $body]);
header('Location: /community');
exit;
}
}
}
$threads = [];
$configCommunity = require __DIR__ . '/../../config/community.php';
$pointsCfg = $configCommunity['points'] ?? [];
$levelsCfg = $configCommunity['levels'] ?? [];
$search = trim((string)($_GET['q'] ?? ''));
if ($pdo) {
$pdo->prepare('CREATE TABLE IF NOT EXISTS forum_posts (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
thread_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
body TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_thread (thread_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci')->execute();
$conditions = [];
$params = [];
if ($search !== '') {
$tokens = preg_split('/\\s+/', $search);
$i = 0;
foreach ($tokens as $tok) {
$tok = trim($tok);
if ($tok === '') continue;
$ph1 = 't' . $i . '_title';
$ph2 = 't' . $i . '_body';
$i++;
$conditions[] = "(ft.title LIKE :$ph1 OR ft.body LIKE :$ph2)";
$params[$ph1] = '%' . $tok . '%';
$params[$ph2] = '%' . $tok . '%';
}
}
$whereSearch = $conditions ? ('AND ' . implode(' AND ', $conditions)) : '';
$sql = "SELECT ft.id, ft.title, ft.body, ft.created_at,
u.id as uid, u.created_at as user_created,
p.display_name,
(SELECT COUNT(*) FROM forum_posts fp WHERE fp.thread_id = ft.id) AS answers,
(SELECT COUNT(*) FROM forum_posts fp2 WHERE fp2.user_id = u.id) +
(SELECT COUNT(*) FROM forum_threads ft2 WHERE ft2.user_id = u.id) AS user_posts
FROM forum_threads ft
JOIN users u ON u.id = ft.user_id
LEFT JOIN user_profiles p ON p.user_id = u.id
WHERE 1=1 $whereSearch
ORDER BY ft.created_at DESC
LIMIT 50";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$threads = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
}
function compute_points(array $row, \PDO $pdo, array $pointsCfg): float {
$uid = (int)$row['uid'];
$threads = (int)($row['user_posts'] ?? 0);
$answers = (int)($row['answers'] ?? 0);
$eventCreated = (int)$pdo->query("SELECT COUNT(*) FROM events WHERE created_by = {$uid}")->fetchColumn();
$eventParticipants = (float)$pdo->query("SELECT COUNT(*) FROM event_participants WHERE user_id = {$uid}")->fetchColumn();
$invites = 0;
return $threads * ($pointsCfg['forum_question'] ?? 0.5)
+ $answers * ($pointsCfg['forum_answer'] ?? 1.0)
+ $eventCreated * ($pointsCfg['event_create'] ?? 1.0)
+ $eventParticipants * ($pointsCfg['event_participation'] ?? 0.1)
+ $invites * ($pointsCfg['invite'] ?? 0.5);
}
function membership_level(float $points, array $levels): array {
usort($levels, fn($a,$b) => ($b['min'] ?? 0) <=> ($a['min'] ?? 0));
foreach ($levels as $lvl) {
if ($points >= (float)($lvl['min'] ?? 0)) {
return [
'label' => $lvl['label'] ?? 'New Daddy',
'icon' => $lvl['icon'] ?? '',
];
}
}
$fallback = $levels ? $levels[count($levels)-1] : ['label' => 'New Daddy','icon' => ''];
return ['label' => $fallback['label'], 'icon' => $fallback['icon'] ?? ''];
}
?>
Community = nl2br(htmlspecialchars(substr($t['body'], 0, 200), ENT_QUOTES)) ?>= strlen($t['body']) > 200 ? '…' : '' ?> Noch keine Fragen gestellt.Forum
= htmlspecialchars($t['title'], ENT_QUOTES) ?>