172 lines
8.8 KiB
PHP
172 lines
8.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/site.php';
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
|
|
boot_site();
|
|
|
|
$formData = [
|
|
'title' => '',
|
|
'category' => '',
|
|
'excerpt' => '',
|
|
'content' => '',
|
|
'cta_text' => 'Kunjungi apknusa.com',
|
|
'cta_url' => APKNUSA_URL,
|
|
'featured' => 0,
|
|
];
|
|
$errors = [];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$result = create_post($_POST);
|
|
if (!empty($result['success'])) {
|
|
header('Location: admin.php?status=created&slug=' . rawurlencode((string)$result['slug']), true, 303);
|
|
exit;
|
|
}
|
|
|
|
$errors = $result['errors'] ?? [];
|
|
$formData = array_merge($formData, $result['input'] ?? []);
|
|
}
|
|
|
|
$posts = fetch_posts();
|
|
$latestSlug = trim((string)($_GET['slug'] ?? ''));
|
|
$status = trim((string)($_GET['status'] ?? ''));
|
|
|
|
render_page_start([
|
|
'title' => 'Kelola Konten Blog',
|
|
'description' => 'Halaman admin sederhana untuk menambah artikel blog yang mengarahkan pembaca ke apknusa.com.',
|
|
'canonical' => canonical_for('admin.php'),
|
|
'robots' => 'noindex,nofollow',
|
|
'keywords' => 'admin blog, tambah artikel apknusa',
|
|
'body_class' => 'admin-page',
|
|
]);
|
|
?>
|
|
<main id="main-content" class="page-wrap py-5">
|
|
<div class="container">
|
|
<?php if ($status === 'created' && $latestSlug !== ''): ?>
|
|
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
|
<div class="toast text-bg-dark border-0" role="status" aria-live="polite" aria-atomic="true" data-autoshow="true" data-bs-delay="4500">
|
|
<div class="d-flex">
|
|
<div class="toast-body">Artikel berhasil ditambahkan dan sitemap.xml sudah diperbarui.</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Tutup"></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row g-4 align-items-start">
|
|
<div class="col-lg-5">
|
|
<section class="panel-card sticky-card">
|
|
<div class="section-heading mb-4">
|
|
<span class="section-kicker">Tambah artikel baru</span>
|
|
<h1 class="section-title mb-2">Workflow admin sederhana</h1>
|
|
<p class="section-copy mb-0">Tulis artikel, tentukan CTA, lalu artikel otomatis masuk ke blog publik dan sitemap.</p>
|
|
</div>
|
|
<div class="alert alert-light border mb-4" role="alert">
|
|
Tautan CTA dibatasi ke <strong>apknusa.com</strong> agar microsite tetap fokus sebagai website pendukung backlink.
|
|
</div>
|
|
<form method="post" action="admin.php" novalidate class="vstack gap-3">
|
|
<div>
|
|
<label class="form-label" for="title">Judul artikel</label>
|
|
<input class="form-control <?= isset($errors['title']) ? 'is-invalid' : '' ?>" type="text" id="title" name="title" value="<?= e((string)$formData['title']) ?>" data-slug-source maxlength="180" placeholder="Contoh: Cara memilih sumber APK yang aman" required>
|
|
<div class="form-text">Slug dibuat otomatis: <span class="slug-preview" data-slug-target>slug-artikel-otomatis</span></div>
|
|
<?php if (isset($errors['title'])): ?><div class="invalid-feedback"><?= e($errors['title']) ?></div><?php endif; ?>
|
|
</div>
|
|
<div>
|
|
<label class="form-label" for="category">Kategori</label>
|
|
<input class="form-control" type="text" id="category" name="category" value="<?= e((string)$formData['category']) ?>" maxlength="80" placeholder="Contoh: Tips Android">
|
|
</div>
|
|
<div>
|
|
<label class="form-label" for="excerpt">Ringkasan singkat</label>
|
|
<textarea class="form-control <?= isset($errors['excerpt']) ? 'is-invalid' : '' ?>" id="excerpt" name="excerpt" rows="3" placeholder="Tuliskan ringkasan artikel untuk kartu blog dan meta description."><?= e((string)$formData['excerpt']) ?></textarea>
|
|
<?php if (isset($errors['excerpt'])): ?><div class="invalid-feedback"><?= e($errors['excerpt']) ?></div><?php endif; ?>
|
|
</div>
|
|
<div>
|
|
<label class="form-label" for="content">Isi artikel</label>
|
|
<textarea class="form-control <?= isset($errors['content']) ? 'is-invalid' : '' ?>" id="content" name="content" rows="10" placeholder="Tulis isi artikel di sini. Gunakan jeda baris kosong antar paragraf."><?= e((string)$formData['content']) ?></textarea>
|
|
<?php if (isset($errors['content'])): ?><div class="invalid-feedback"><?= e($errors['content']) ?></div><?php endif; ?>
|
|
</div>
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="cta_text">Teks CTA</label>
|
|
<input class="form-control <?= isset($errors['cta_text']) ? 'is-invalid' : '' ?>" type="text" id="cta_text" name="cta_text" value="<?= e((string)$formData['cta_text']) ?>" maxlength="120">
|
|
<?php if (isset($errors['cta_text'])): ?><div class="invalid-feedback"><?= e($errors['cta_text']) ?></div><?php endif; ?>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="cta_url">URL CTA</label>
|
|
<input class="form-control <?= isset($errors['cta_url']) ? 'is-invalid' : '' ?>" type="url" id="cta_url" name="cta_url" value="<?= e((string)$formData['cta_url']) ?>" placeholder="https://apknusa.com">
|
|
<?php if (isset($errors['cta_url'])): ?><div class="invalid-feedback"><?= e($errors['cta_url']) ?></div><?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="featured" name="featured" value="1" <?= !empty($formData['featured']) ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="featured">Jadikan artikel unggulan di halaman utama</label>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2 pt-2">
|
|
<button class="btn btn-dark" type="submit">Simpan artikel</button>
|
|
<a class="btn btn-outline-dark" href="blog.php">Lihat blog publik</a>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</div>
|
|
<div class="col-lg-7">
|
|
<section class="panel-card mb-4">
|
|
<div class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center gap-3">
|
|
<div>
|
|
<span class="section-kicker">Status konten</span>
|
|
<h2 class="section-title mb-1">Artikel yang sudah tayang</h2>
|
|
<p class="section-copy mb-0">Daftar ini memperlihatkan konten yang aktif di blog dan ikut masuk ke sitemap.</p>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<a class="btn btn-outline-dark btn-sm" href="sitemap.xml">Buka sitemap</a>
|
|
<a class="btn btn-outline-dark btn-sm" href="robots.txt">Buka robots</a>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="table-card">
|
|
<div class="table-responsive">
|
|
<table class="table align-middle mb-0 admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Artikel</th>
|
|
<th>Kategori</th>
|
|
<th>CTA</th>
|
|
<th>Tayang</th>
|
|
<th class="text-end">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($posts as $post): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="fw-semibold"><?= e((string)$post['title']) ?></div>
|
|
<div class="small text-secondary"><?= e((string)$post['slug']) ?></div>
|
|
</td>
|
|
<td><span class="tag-badge"><?= e((string)$post['category']) ?></span></td>
|
|
<td>
|
|
<div class="small fw-semibold"><?= e((string)$post['cta_text']) ?></div>
|
|
<div class="small text-secondary text-break"><?= e((string)$post['cta_url']) ?></div>
|
|
</td>
|
|
<td>
|
|
<div class="small"><?= e((string)format_article_date((string)$post['published_at'])) ?></div>
|
|
<?php if (!empty($post['featured'])): ?><span class="small text-secondary">Unggulan</span><?php endif; ?>
|
|
</td>
|
|
<td class="text-end">
|
|
<div class="d-inline-flex gap-2">
|
|
<a class="btn btn-outline-dark btn-sm" href="<?= e(post_url($post)) ?>">Detail</a>
|
|
<a class="btn btn-dark btn-sm" href="<?= e((string)$post['cta_url']) ?>" target="_blank" rel="noopener noreferrer">CTA</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<?php render_page_end(); ?>
|