154 lines
5.5 KiB
PHP
154 lines
5.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/app.php';
|
|
ensure_tables();
|
|
|
|
$pageTitle = 'Build Detail';
|
|
$active = 'builds';
|
|
$pdo = db();
|
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
$notice = '';
|
|
$errors = [];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$author = trim($_POST['author'] ?? '');
|
|
$body = trim($_POST['body'] ?? '');
|
|
|
|
if ($author === '') {
|
|
$errors[] = 'Name is required for a comment.';
|
|
}
|
|
if ($body === '' || strlen($body) < 3) {
|
|
$errors[] = 'Comment must be at least 3 characters.';
|
|
}
|
|
|
|
if (!$errors && $id) {
|
|
$stmt = $pdo->prepare("INSERT INTO build_comments (build_id, author, body) VALUES (:build_id, :author, :body)");
|
|
$stmt->execute([
|
|
':build_id' => $id,
|
|
':author' => $author,
|
|
':body' => $body,
|
|
]);
|
|
header('Location: build.php?id=' . $id . '&commented=1');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM builds WHERE id = :id");
|
|
$stmt->execute([':id' => $id]);
|
|
$build = $stmt->fetch();
|
|
|
|
if (!$build) {
|
|
$pageTitle = 'Build Not Found';
|
|
}
|
|
|
|
$comments = [];
|
|
if ($build) {
|
|
$stmt = $pdo->prepare("SELECT * FROM build_comments WHERE build_id = :id ORDER BY created_at DESC");
|
|
$stmt->execute([':id' => $id]);
|
|
$comments = $stmt->fetchAll();
|
|
}
|
|
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
|
|
<?php if (!$build): ?>
|
|
<div class="app-card">
|
|
<h1 class="h4">Build not found</h1>
|
|
<p class="muted">The build you requested does not exist. Try browsing the build library.</p>
|
|
<a class="btn btn-outline-light" href="builds.php">Back to builds</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-3">
|
|
<div>
|
|
<span class="badge badge-soft mb-2"><?= h($build['game']) ?></span>
|
|
<?php if (!empty($build['patch'])): ?>
|
|
<span class="badge badge-soft mb-2">Patch <?= h($build['patch']) ?></span>
|
|
<?php endif; ?>
|
|
<h1 class="h3 mb-1"><?= h($build['title']) ?></h1>
|
|
<p class="muted mb-0"><?= h($build['class_name']) ?> · Authored by <?= h($build['author']) ?> · <?= h(format_date($build['created_at'])) ?></p>
|
|
</div>
|
|
<a class="btn btn-outline-light" href="create_build.php">Publish new build</a>
|
|
</div>
|
|
|
|
<?php if (!empty($_GET['created'])): ?>
|
|
<div class="alert alert-success alert-dismissible show" role="alert" data-autohide="true">
|
|
Build published successfully. Share it with the community.
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (!empty($_GET['commented'])): ?>
|
|
<div class="alert alert-success alert-dismissible show" role="alert" data-autohide="true">
|
|
Comment added. Thanks for contributing.
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($errors): ?>
|
|
<div class="alert alert-warning" role="alert">
|
|
<?= h(implode(' ', $errors)) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-lg-7">
|
|
<div class="app-card h-100">
|
|
<h2 class="h5">Build summary</h2>
|
|
<p class="muted"><?= h($build['summary'] ?: 'No summary provided yet.') ?></p>
|
|
<hr class="border-secondary">
|
|
<h3 class="h6">Skill priorities</h3>
|
|
<p><?= nl2br(h($build['skills'] ?: 'List core skills, rotation, and passive synergies.')) ?></p>
|
|
<h3 class="h6 mt-3">Gear & stats</h3>
|
|
<p><?= nl2br(h($build['gear'] ?: 'Highlight items, stat thresholds, and legendary priorities.')) ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5">
|
|
<div class="app-card h-100">
|
|
<h2 class="h5">Patch impact notes</h2>
|
|
<p class="muted">Track changes and explain why this build remains optimal.</p>
|
|
<ul class="list-unstyled mb-0">
|
|
<li class="mb-2"><span class="tag">Meta</span> Recommended for current season.</li>
|
|
<li class="mb-2"><span class="tag">Stats</span> Focus on cooldown + crit.</li>
|
|
<li><span class="tag">Tips</span> Positioning advice included in skills block.</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="app-card">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h2 class="h5 mb-0">Community comments</h2>
|
|
<span class="muted"><?= count($comments) ?> comments</span>
|
|
</div>
|
|
<form method="post" class="mb-4">
|
|
<div class="row g-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label">Name</label>
|
|
<input class="form-control" type="text" name="author" required>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<label class="form-label">Comment</label>
|
|
<input class="form-control" type="text" name="body" maxlength="1000" required>
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-primary mt-3" type="submit">Add comment</button>
|
|
</form>
|
|
|
|
<?php if (!$comments): ?>
|
|
<p class="muted mb-0">No comments yet. Share first impressions.</p>
|
|
<?php else: ?>
|
|
<div class="d-grid gap-3">
|
|
<?php foreach ($comments as $comment): ?>
|
|
<div class="app-card">
|
|
<div class="d-flex justify-content-between">
|
|
<strong><?= h($comment['author']) ?></strong>
|
|
<span class="muted"><?= h(format_date($comment['created_at'])) ?></span>
|
|
</div>
|
|
<p class="mb-0"><?= h($comment['body']) ?></p>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|