first
19
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/backup/
|
||||||
|
/cache/
|
||||||
|
/vendor/
|
||||||
|
.DS_Store
|
||||||
|
content/posts/.scheduler.lock
|
||||||
|
/data
|
||||||
|
./data
|
||||||
|
/data/
|
||||||
|
data/*
|
||||||
|
config
|
||||||
|
/config/
|
||||||
|
/config
|
||||||
|
./config
|
||||||
|
config/
|
||||||
|
/backup/
|
||||||
|
backup
|
||||||
|
backup/
|
||||||
|
/backup
|
||||||
|
./backup
|
||||||
44
.htaccess
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
Options -Indexes
|
||||||
|
|
||||||
|
# Cache static assets
|
||||||
|
<IfModule mod_expires.c>
|
||||||
|
ExpiresActive On
|
||||||
|
ExpiresByType font/woff2 "access plus 3 months"
|
||||||
|
ExpiresByType font/woff "access plus 3 months"
|
||||||
|
ExpiresByType font/ttf "access plus 3 months"
|
||||||
|
ExpiresByType text/css "access plus 1 month"
|
||||||
|
ExpiresByType application/javascript "access plus 1 month"
|
||||||
|
ExpiresByType image/webp "access plus 1 month"
|
||||||
|
ExpiresByType image/png "access plus 1 month"
|
||||||
|
ExpiresByType image/jpeg "access plus 1 month"
|
||||||
|
ExpiresByType image/gif "access plus 1 month"
|
||||||
|
ExpiresByType image/svg+xml "access plus 1 month"
|
||||||
|
ExpiresByType image/x-icon "access plus 1 month"
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
# Redirect sitemap.xml to sitemap.php
|
||||||
|
RewriteRule ^sitemap\.xml$ sitemap.php [L,QSA]
|
||||||
|
|
||||||
|
# Block access to sensitive directories and files
|
||||||
|
RewriteRule ^config/ - [F,L]
|
||||||
|
RewriteRule ^data/ - [F,L]
|
||||||
|
RewriteRule ^cache/ - [F,L]
|
||||||
|
RewriteRule ^content/autosaves/ - [F,L]
|
||||||
|
RewriteRule ^content/layouts/ - [F,L]
|
||||||
|
RewriteRule ^content/functions\.php$ - [F,L]
|
||||||
|
RewriteRule ^.*\.md$ - [F,L]
|
||||||
|
RewriteRule ^content/images/.*\.ph(p[0-9]?|tml)$ - [F,L]
|
||||||
|
|
||||||
|
# To restrict /admin access by IP address, uncomment the RewriteCond and RewriteRule lines then replace 11\.22\.33\.44 with the public IP address to be allowed (backslashes need to remain - just replace the numbers). To add more than one IP, copy and paste the entire line, then change the IP.
|
||||||
|
# RewriteCond %{REMOTE_ADDR} !^11\.22\.33\.44$
|
||||||
|
# RewriteRule ^admin/ - [F,L]
|
||||||
|
|
||||||
|
# Allow direct access to existing files and folders
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -d
|
||||||
|
RewriteRule ^ - [L]
|
||||||
|
|
||||||
|
# Everything else goes through the front controller
|
||||||
|
RewriteRule ^ index.php [L,QSA]
|
||||||
23
404.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/functions.php';
|
||||||
|
require_setup_redirect();
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['font_stack'] ?? 'sans');
|
||||||
|
$pageTitle = t('frontend.page_not_found');
|
||||||
|
$metaDescription = '';
|
||||||
|
|
||||||
|
http_response_code(404);
|
||||||
|
require __DIR__ . '/includes/header.php';
|
||||||
|
render_masthead_layout($config, ['page' => $page ?? null, 'is404' => true]);
|
||||||
|
?>
|
||||||
|
<main>
|
||||||
|
<h1><?= e(t('frontend.page_not_found')) ?></h1>
|
||||||
|
<p><?= e(t('frontend.page_not_found_detail')) ?></p>
|
||||||
|
</main>
|
||||||
|
<?php render_footer_layout($config, ['page' => $page ?? null]); ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
19
LICENSE.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Pure Blog License v1.2
|
||||||
|
|
||||||
|
Copyright © 2026 [Kev Quirk](https://kevquirk.com)
|
||||||
|
|
||||||
|
Pure Blog is free to use, modify, and self-host.
|
||||||
|
|
||||||
|
You are **NOT** allowed to:
|
||||||
|
|
||||||
|
1. Offer Pure Blog as a commercial hosted platform or service where you operate the infrastructure on behalf of third parties for a fee (free hosting is permitted for friends and family).
|
||||||
|
2. Sell Pure Blog itself, or build a product where access to Pure Blog is what customers are paying for.
|
||||||
|
3. Remove attribution to the original author.
|
||||||
|
|
||||||
|
You **ARE** allowed to:
|
||||||
|
|
||||||
|
1. Use Pure Blog to run your own website, blog, or community platform — whether personal or commercial.
|
||||||
|
2. Modify the code for your own use.
|
||||||
|
3. Share modified versions, as long as this license stays with it.
|
||||||
|
|
||||||
|
Pure Blog is provided as-is with no warranty whatsoever.
|
||||||
38
README.md
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Pure Blog
|
||||||
|
|
||||||
|
Pure Blog is a simple, flat‑file blogging platform with a Markdown‑first editor and a lightweight admin area. It stores posts and pages as Markdown files on disk—no database required.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Flat-file content using Markdown and front matter.
|
||||||
|
- A clean, distraction-free admin dashboard for writing and organising posts/pages.
|
||||||
|
- Draft previews so you can check your work before publishing.
|
||||||
|
- Optional tags and tag archives for grouping related posts.
|
||||||
|
- Automatic pagination when your post list grows long.
|
||||||
|
- An RSS feed so readers can follow along however they like.
|
||||||
|
- Built-in search that helps readers find exactly what they’re looking for.
|
||||||
|
- A settings page that allows you to customise and configure your blog.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- PHP 8.1 or newer
|
||||||
|
- A standard web server (Apache or Nginx)
|
||||||
|
- **Required PHP extensions:** `mbstring`, `xml`
|
||||||
|
- **Recommended PHP extensions:** `curl`, `zip`
|
||||||
|
- Write access to `/config`, `/content`, and `/data`
|
||||||
|
|
||||||
|
> **Nginx users:** you will also need `php-fpm` configured alongside Nginx, as PHP-FPM is required to process PHP when not using Apache.
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
All you need to run Pure Blog is a host that supports PHP (pretty much all of them do). Once you have that, all you need to do is:
|
||||||
|
|
||||||
|
1. Download the Pure Blog package.
|
||||||
|
2. Extract the zip file and upload the contents to your web server.
|
||||||
|
3. Visit the URL of your blog and setup will automatically start.
|
||||||
|
4. Once your site is setup, visit `/admin` and login to your new blog.
|
||||||
|
|
||||||
|
## Content
|
||||||
|
Posts live in `content/posts` and pages live in `content/pages`. When images are uploaded they are stored in `/content/images/[post/page-slug]`.
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
- Pure Blog is intentionally minimal and designed for personal sites.
|
||||||
|
- HTML in Markdown is supported.
|
||||||
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
3.9.2
|
||||||
82
admin/autosave.php
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_method')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = isset($_POST['csrf_token']) ? (string) $_POST['csrf_token'] : '';
|
||||||
|
$sessionToken = $_SESSION['csrf_token'] ?? '';
|
||||||
|
if ($token === '' || !is_string($sessionToken) || !hash_equals($sessionToken, $token)) {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_csrf')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editorType = trim($_POST['editor_type'] ?? 'post');
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$action = trim($_POST['action'] ?? 'save');
|
||||||
|
|
||||||
|
if ($slug === '') {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_slug')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($editorType, ['post', 'page'], true)) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_slug')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_safe_image_slug($slug)) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_slug')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$autosaveDir = PUREBLOG_BASE_PATH . '/content/autosaves';
|
||||||
|
$autosaveFile = $autosaveDir . '/' . $editorType . '-' . $slug . '.json';
|
||||||
|
|
||||||
|
if ($action === 'discard') {
|
||||||
|
if (is_file($autosaveFile)) {
|
||||||
|
@unlink($autosaveFile);
|
||||||
|
}
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the autosaves directory exists.
|
||||||
|
if (!is_dir($autosaveDir)) {
|
||||||
|
mkdir($autosaveDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($editorType === 'page') {
|
||||||
|
$data = [
|
||||||
|
'timestamp' => time(),
|
||||||
|
'title' => trim($_POST['title'] ?? ''),
|
||||||
|
'content' => trim($_POST['content'] ?? ''),
|
||||||
|
'description' => trim($_POST['description'] ?? ''),
|
||||||
|
'status' => trim($_POST['status'] ?? 'draft'),
|
||||||
|
'include_in_nav' => trim($_POST['include_in_nav'] ?? 'yes'),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$data = [
|
||||||
|
'timestamp' => time(),
|
||||||
|
'title' => trim($_POST['title'] ?? ''),
|
||||||
|
'content' => trim($_POST['content'] ?? ''),
|
||||||
|
'description' => trim($_POST['description'] ?? ''),
|
||||||
|
'status' => trim($_POST['status'] ?? 'draft'),
|
||||||
|
'tags' => trim($_POST['tags'] ?? ''),
|
||||||
|
'date' => trim($_POST['date'] ?? ''),
|
||||||
|
'layout' => trim($_POST['post_layout'] ?? ''),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$written = file_put_contents($autosaveFile, json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||||
|
echo json_encode($written !== false ? ['success' => true] : ['success' => false, 'error' => t('admin.editor.error_autosave_write')]);
|
||||||
9
admin/bootstrap.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/../functions.php';
|
||||||
|
require_setup_redirect();
|
||||||
|
|
||||||
|
start_admin_session();
|
||||||
|
require_admin_login();
|
||||||
461
admin/content.php
Normal file
|
|
@ -0,0 +1,461 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$availableLayouts = get_layouts();
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
|
||||||
|
$defaultTab = $blogPostsEnabled ? 'posts' : 'pages';
|
||||||
|
$tab = (string) ($_GET['tab'] ?? $defaultTab);
|
||||||
|
if (!$blogPostsEnabled) {
|
||||||
|
$tab = 'pages';
|
||||||
|
} elseif (!in_array($tab, ['posts', 'pages'], true)) {
|
||||||
|
$tab = 'posts';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posts data
|
||||||
|
$perPage = 20;
|
||||||
|
$page = max(1, (int) ($_GET['page'] ?? 1));
|
||||||
|
$search = trim((string) ($_GET['q'] ?? ''));
|
||||||
|
$filterYear = isset($_GET['year']) ? (int) $_GET['year'] : 0;
|
||||||
|
$filterMonth = isset($_GET['month']) ? (int) $_GET['month'] : 0;
|
||||||
|
$filterTag = trim((string) ($_GET['tag'] ?? ''));
|
||||||
|
$filterStatus = trim((string) ($_GET['status'] ?? ''));
|
||||||
|
$filterLayout = trim((string) ($_GET['layout'] ?? ''));
|
||||||
|
$filterSince = isset($_GET['since']) ? (int) $_GET['since'] : 0;
|
||||||
|
if (!in_array($filterStatus, ['draft', 'scheduled', 'published'], true)) {
|
||||||
|
$filterStatus = '';
|
||||||
|
}
|
||||||
|
if ($filterYear < 2000 || $filterYear > 2100) {
|
||||||
|
$filterYear = 0;
|
||||||
|
}
|
||||||
|
if ($filterMonth < 1 || $filterMonth > 12) {
|
||||||
|
$filterMonth = 0;
|
||||||
|
}
|
||||||
|
if ($filterSince < 0 || $filterSince > time()) {
|
||||||
|
$filterSince = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$allPosts = get_all_posts_meta(true);
|
||||||
|
usort($allPosts, function (array $a, array $b): int {
|
||||||
|
$order = ['draft' => 0, 'scheduled' => 1, 'published' => 2];
|
||||||
|
$aOrder = $order[$a['status'] ?? 'draft'] ?? 0;
|
||||||
|
$bOrder = $order[$b['status'] ?? 'draft'] ?? 0;
|
||||||
|
if ($aOrder !== $bOrder) {
|
||||||
|
return $aOrder <=> $bOrder;
|
||||||
|
}
|
||||||
|
// Scheduled: soonest first so you see what's coming up next
|
||||||
|
if (($a['status'] ?? '') === 'scheduled') {
|
||||||
|
return ($a['timestamp'] <=> $b['timestamp']);
|
||||||
|
}
|
||||||
|
return ($b['timestamp'] <=> $a['timestamp']);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build filter option lists from the unfiltered set
|
||||||
|
$availableYears = [];
|
||||||
|
$availableTags = [];
|
||||||
|
foreach ($allPosts as $p) {
|
||||||
|
$ts = (int) ($p['timestamp'] ?? 0);
|
||||||
|
if ($ts > 0) {
|
||||||
|
$availableYears[(int) (new DateTimeImmutable('@' . $ts))->format('Y')] = true;
|
||||||
|
}
|
||||||
|
foreach (($p['tags'] ?? []) as $t) {
|
||||||
|
$t = trim((string) $t);
|
||||||
|
if ($t !== '') {
|
||||||
|
$slug = normalize_tag($t);
|
||||||
|
if ($slug !== '') {
|
||||||
|
$availableTags[$slug] ??= $t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
krsort($availableYears);
|
||||||
|
ksort($availableTags);
|
||||||
|
$availableYears = array_keys($availableYears);
|
||||||
|
|
||||||
|
$usedLayouts = [];
|
||||||
|
foreach ($allPosts as $p) {
|
||||||
|
$l = trim((string) ($p['layout'] ?? ''));
|
||||||
|
if ($l !== '') {
|
||||||
|
$usedLayouts[$l] ??= ucfirst($l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($availableLayouts as $lay) {
|
||||||
|
if (isset($usedLayouts[$lay['name']])) {
|
||||||
|
$usedLayouts[$lay['name']] = $lay['label'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ksort($usedLayouts);
|
||||||
|
if ($filterLayout !== '' && !isset($usedLayouts[$filterLayout])) {
|
||||||
|
$filterLayout = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply filters
|
||||||
|
$filteredPosts = filter_posts_by_query($allPosts, $search);
|
||||||
|
if ($filterYear > 0 || $filterMonth > 0) {
|
||||||
|
$filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterYear, $filterMonth): bool {
|
||||||
|
$ts = (int) ($post['timestamp'] ?? 0);
|
||||||
|
if ($ts === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$dt = new DateTimeImmutable('@' . $ts);
|
||||||
|
if ($filterYear > 0 && (int) $dt->format('Y') !== $filterYear) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($filterMonth > 0 && (int) $dt->format('n') !== $filterMonth) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if ($filterTag !== '') {
|
||||||
|
$filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterTag): bool {
|
||||||
|
$tags = $post['tags'] ?? [];
|
||||||
|
return is_array($tags) && in_array(normalize_tag($filterTag), array_map(fn($t) => normalize_tag((string) $t), $tags), true);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if ($filterStatus !== '') {
|
||||||
|
$filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterStatus): bool {
|
||||||
|
return ($post['status'] ?? '') === $filterStatus;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if ($filterSince > 0) {
|
||||||
|
$filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterSince): bool {
|
||||||
|
return (int) ($post['timestamp'] ?? 0) >= $filterSince;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if ($filterLayout !== '') {
|
||||||
|
$filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterLayout): bool {
|
||||||
|
return trim((string) ($post['layout'] ?? '')) === $filterLayout;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a human-readable label and clear-URL for any active filter
|
||||||
|
$filterLabel = '';
|
||||||
|
$filterClearUrl = '';
|
||||||
|
$anyFilter = $filterYear > 0 || $filterMonth > 0 || $filterTag !== '' || $filterStatus !== '' || $filterSince > 0 || $filterLayout !== '';
|
||||||
|
if ($anyFilter) {
|
||||||
|
$parts = [];
|
||||||
|
if ($filterYear > 0 && $filterMonth > 0) {
|
||||||
|
$parts[] = t('date.months.' . ($filterMonth - 1)) . ' ' . $filterYear;
|
||||||
|
} elseif ($filterYear > 0) {
|
||||||
|
$parts[] = (string) $filterYear;
|
||||||
|
} elseif ($filterMonth > 0) {
|
||||||
|
$parts[] = t('date.months.' . ($filterMonth - 1));
|
||||||
|
}
|
||||||
|
if ($filterTag !== '') {
|
||||||
|
$parts[] = $availableTags[$filterTag] ?? $filterTag;
|
||||||
|
}
|
||||||
|
if ($filterStatus !== '') {
|
||||||
|
$parts[] = t('admin.editor.status_' . $filterStatus);
|
||||||
|
}
|
||||||
|
if ($filterLayout !== '') {
|
||||||
|
$parts[] = $usedLayouts[$filterLayout];
|
||||||
|
}
|
||||||
|
if ($filterSince > 0 && $filterYear === 0) {
|
||||||
|
$parts[] = t('admin.content.filter_recent');
|
||||||
|
}
|
||||||
|
$filterLabel = implode(', ', $parts);
|
||||||
|
$clearParams = array_filter(['tab' => $tab, 'q' => $search !== '' ? $search : null]);
|
||||||
|
$filterClearUrl = base_path() . '/admin/content.php?' . http_build_query($clearParams);
|
||||||
|
}
|
||||||
|
$detailsOpen = $anyFilter || $search !== '';
|
||||||
|
|
||||||
|
$totalPosts = count($filteredPosts);
|
||||||
|
$totalPages = $totalPosts > 0 ? (int) ceil($totalPosts / $perPage) : 1;
|
||||||
|
$offset = ($page - 1) * $perPage;
|
||||||
|
$posts = array_slice($filteredPosts, $offset, $perPage);
|
||||||
|
|
||||||
|
// Pages data
|
||||||
|
$pages = get_all_pages(true);
|
||||||
|
usort($pages, function (array $a, array $b): int {
|
||||||
|
if ($a['status'] !== $b['status']) {
|
||||||
|
return $a['status'] === 'draft' ? -1 : 1;
|
||||||
|
}
|
||||||
|
return ($a['title'] <=> $b['title']);
|
||||||
|
});
|
||||||
|
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
$postDateFmt = site_date_format($config);
|
||||||
|
if (strpbrk($postDateFmt, 'HhGgi') === false) {
|
||||||
|
$postDateFmt .= ' @ H:i';
|
||||||
|
}
|
||||||
|
$adminTitle = t('admin.content.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e($tab === 'pages' ? t('admin.content.tab_pages') : t('admin.content.tab_posts')) ?></h1>
|
||||||
|
<nav class="admin-actions">
|
||||||
|
<?php if ($tab === 'pages'): ?>
|
||||||
|
<a class="button save" href="<?= base_path() ?>/admin/edit-page.php?action=new"><svg class="icon" aria-hidden="true"><use href="#icon-file-plus-corner"></use></svg> <?= e(t('admin.content.new_page')) ?></a>
|
||||||
|
<?php elseif ($availableLayouts): ?>
|
||||||
|
<button type="button" class="button save js-open-layout-picker"><svg class="icon" aria-hidden="true"><use href="#icon-file-plus-corner"></use></svg> <?= e(t('admin.content.new_post')) ?></button>
|
||||||
|
<?php else: ?>
|
||||||
|
<a class="button save" href="<?= base_path() ?>/admin/edit-post.php?action=new"><svg class="icon" aria-hidden="true"><use href="#icon-file-plus-corner"></use></svg> <?= e(t('admin.content.new_post')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</nav>
|
||||||
|
<?php if ($tab === 'posts'): ?>
|
||||||
|
|
||||||
|
<?php if (!empty($_GET['saved'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.content.notice_post_saved')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['deleted'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.content.notice_post_deleted')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<details class="content-filter"<?= $detailsOpen ? ' open' : '' ?>>
|
||||||
|
<summary class="content-filter-summary">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-search"></use></svg>
|
||||||
|
<?= e(t('admin.content.filter_title')) ?>
|
||||||
|
<?php if ($filterLabel !== ''): ?>
|
||||||
|
<span class="content-filter-active-label"><?= e($filterLabel) ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</summary>
|
||||||
|
<form method="get" class="content-filter-form">
|
||||||
|
<input type="hidden" name="tab" value="posts">
|
||||||
|
|
||||||
|
<div class="content-filter-row">
|
||||||
|
<div class="content-filter-search">
|
||||||
|
<label for="filter-search"><?= e(t('admin.content.search_label')) ?></label>
|
||||||
|
<input type="search" id="filter-search" name="q" value="<?= e($search) ?>" placeholder="<?= e(t('admin.content.search_placeholder')) ?>" autocomplete="off">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content-filter-selects">
|
||||||
|
<?php if ($availableYears): ?>
|
||||||
|
<div class="content-filter-field">
|
||||||
|
<label for="filter-year"><?= e(t('admin.content.filter_year')) ?></label>
|
||||||
|
<select id="filter-year" name="year">
|
||||||
|
<option value=""><?= e(t('admin.content.filter_all_years')) ?></option>
|
||||||
|
<?php foreach ($availableYears as $y): ?>
|
||||||
|
<option value="<?= e((string) $y) ?>"<?= $filterYear === $y ? ' selected' : '' ?>><?= e((string) $y) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="content-filter-field">
|
||||||
|
<label for="filter-month"><?= e(t('admin.content.filter_month')) ?></label>
|
||||||
|
<select id="filter-month" name="month">
|
||||||
|
<option value=""><?= e(t('admin.content.filter_all_months')) ?></option>
|
||||||
|
<?php for ($m = 1; $m <= 12; $m++): ?>
|
||||||
|
<option value="<?= $m ?>"<?= $filterMonth === $m ? ' selected' : '' ?>><?= e(t('date.months.' . ($m - 1))) ?></option>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($availableTags): ?>
|
||||||
|
<div class="content-filter-field">
|
||||||
|
<label for="filter-tag"><?= e(t('admin.content.filter_tag')) ?></label>
|
||||||
|
<select id="filter-tag" name="tag">
|
||||||
|
<option value=""><?= e(t('admin.content.filter_all_tags')) ?></option>
|
||||||
|
<?php foreach ($availableTags as $tagSlug => $tagDisplayName): ?>
|
||||||
|
<option value="<?= e((string) $tagSlug) ?>"<?= $filterTag === (string) $tagSlug ? ' selected' : '' ?>><?= e($tagDisplayName) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="content-filter-field">
|
||||||
|
<label for="filter-status"><?= e(t('admin.content.filter_status')) ?></label>
|
||||||
|
<select id="filter-status" name="status">
|
||||||
|
<option value=""><?= e(t('admin.content.filter_all_statuses')) ?></option>
|
||||||
|
<option value="published"<?= $filterStatus === 'published' ? ' selected' : '' ?>><?= e(t('admin.editor.status_published')) ?></option>
|
||||||
|
<option value="scheduled"<?= $filterStatus === 'scheduled' ? ' selected' : '' ?>><?= e(t('admin.editor.status_scheduled')) ?></option>
|
||||||
|
<option value="draft"<?= $filterStatus === 'draft' ? ' selected' : '' ?>><?= e(t('admin.editor.status_draft')) ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($usedLayouts): ?>
|
||||||
|
<div class="content-filter-field">
|
||||||
|
<label for="filter-layout"><?= e(t('admin.content.filter_layout')) ?></label>
|
||||||
|
<select id="filter-layout" name="layout">
|
||||||
|
<option value=""><?= e(t('admin.content.filter_all_layouts')) ?></option>
|
||||||
|
<?php foreach ($usedLayouts as $layoutName => $layoutLabel): ?>
|
||||||
|
<option value="<?= e($layoutName) ?>"<?= $filterLayout === $layoutName ? ' selected' : '' ?>><?= e($layoutLabel) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="content-filter-actions">
|
||||||
|
<button type="submit"><?= e(t('admin.content.filter_apply')) ?></button>
|
||||||
|
<?php if ($detailsOpen): ?>
|
||||||
|
<a class="delete" href="<?= e(base_path() . '/admin/content.php?tab=' . urlencode($tab)) ?>"><?= e(t('admin.content.filter_clear')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<?php if (!$posts): ?>
|
||||||
|
<?php if ($filterLabel !== '' || $search !== ''): ?>
|
||||||
|
<p><?= e(t('admin.content.no_posts_filtered', ['label' => $filterLabel !== '' ? $filterLabel : $search])) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<p><?= e(t('admin.content.no_posts')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul class="admin-list">
|
||||||
|
<?php foreach ($posts as $post): ?>
|
||||||
|
<?php
|
||||||
|
$postSlug = (string) ($post['slug'] ?? '');
|
||||||
|
$postStatus = (string) ($post['status'] ?? 'draft');
|
||||||
|
$postViewUrl = ($postStatus === 'published')
|
||||||
|
? (base_path() . '/' . rawurlencode($postSlug))
|
||||||
|
: (base_path() . '/admin/preview.php?type=post&slug=' . urlencode($postSlug));
|
||||||
|
$postTags = array_values(array_filter(array_map('trim', (array) ($post['tags'] ?? []))));
|
||||||
|
?>
|
||||||
|
<li class="admin-list-item">
|
||||||
|
<a class="admin-list-title" href="<?= base_path() ?>/admin/edit-post.php?slug=<?= e($post['slug']) ?>">
|
||||||
|
<?= e($post['title']) ?>
|
||||||
|
</a>
|
||||||
|
<div class="admin-list-meta">
|
||||||
|
<span><svg class="icon" aria-hidden="true"><use href="#icon-calendar"></use></svg> <?= e(format_datetime_for_display((string) ($post['date'] ?? ''), $config, $postDateFmt)) ?></span>
|
||||||
|
<span class="status <?= e($post['status']) ?>"><svg class="icon" aria-hidden="true"><use href="#icon-toggle-right"></use></svg> <?= e(t('admin.editor.status_' . $post['status'])) ?></span>
|
||||||
|
<a class="admin-list-view" href="<?= e($postViewUrl) ?>" target="_blank" rel="noopener noreferrer" title="<?= e(t('admin.content.view_post')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg> <?= e(t('admin.content.view_post')) ?>
|
||||||
|
</a>
|
||||||
|
<?php if ($postTags): ?>
|
||||||
|
<span class="admin-list-tags">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-tag"></use></svg>
|
||||||
|
<?php foreach ($postTags as $idx => $tag): ?>
|
||||||
|
<?php $tagSlug = normalize_tag($tag); ?>
|
||||||
|
<a class="admin-tag-link<?= $filterTag === $tagSlug ? ' active' : '' ?>" href="<?= base_path() ?>/admin/content.php?tab=posts&tag=<?= urlencode($tagSlug) ?>"><?= e($tag) ?></a><?= $idx < count($postTags) - 1 ? ',' : '' ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php if ($totalPages > 1): ?>
|
||||||
|
<?php
|
||||||
|
$pageParams = ['tab' => 'posts'];
|
||||||
|
if ($filterYear > 0) { $pageParams['year'] = $filterYear; }
|
||||||
|
if ($filterMonth > 0) { $pageParams['month'] = $filterMonth; }
|
||||||
|
if ($filterTag !== '') { $pageParams['tag'] = $filterTag; }
|
||||||
|
if ($filterStatus !== '') { $pageParams['status'] = $filterStatus; }
|
||||||
|
if ($filterLayout !== '') { $pageParams['layout'] = $filterLayout; }
|
||||||
|
if ($filterSince > 0) { $pageParams['since'] = $filterSince; }
|
||||||
|
if ($search !== '') { $pageParams['q'] = $search; }
|
||||||
|
?>
|
||||||
|
<nav class="pagination">
|
||||||
|
<?php if ($page > 1): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/content.php?<?= e(http_build_query($pageParams + ['page' => $page - 1])) ?>"><?= e(t('admin.content.pagination_newer')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($page < $totalPages): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/content.php?<?= e(http_build_query($pageParams + ['page' => $page + 1])) ?>"><?= e(t('admin.content.pagination_older')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</nav>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
|
||||||
|
<?php if (!empty($_GET['saved'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.content.notice_page_saved')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['deleted'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.content.notice_page_deleted')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!$pages): ?>
|
||||||
|
<p><?= e(t('admin.content.no_pages')) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php
|
||||||
|
$homepageSlug = trim((string) ($config['homepage_slug'] ?? 'home'));
|
||||||
|
$blogPageSlug = trim((string) ($config['blog_page_slug'] ?? 'blog'));
|
||||||
|
$searchPageSlug = trim((string) ($config['search_page_slug'] ?? 'search'));
|
||||||
|
$blogFeedHidden = ($blogPageSlug === '__hidden__');
|
||||||
|
?>
|
||||||
|
<ul class="admin-list">
|
||||||
|
<?php foreach ($pages as $page): ?>
|
||||||
|
<?php
|
||||||
|
$pageSlug = (string) ($page['slug'] ?? '');
|
||||||
|
$pageStatus = (string) ($page['status'] ?? 'draft');
|
||||||
|
$isHome = $homepageSlug !== '' && $pageSlug === $homepageSlug;
|
||||||
|
$isBlog = !$blogFeedHidden && $blogPageSlug !== '' && $pageSlug === $blogPageSlug;
|
||||||
|
$isSearch = $searchPageSlug !== '' && $pageSlug === $searchPageSlug;
|
||||||
|
if ($pageStatus === 'published') {
|
||||||
|
$pageViewUrl = $isHome ? (base_path() . '/') : (base_path() . '/' . rawurlencode($pageSlug));
|
||||||
|
} else {
|
||||||
|
$pageViewUrl = base_path() . '/admin/preview.php?type=page&slug=' . urlencode($pageSlug);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<li class="admin-list-item">
|
||||||
|
<a class="admin-list-title" href="<?= base_path() ?>/admin/edit-page.php?slug=<?= e($page['slug']) ?>">
|
||||||
|
<?= e($page['title']) ?>
|
||||||
|
</a>
|
||||||
|
<div class="admin-list-meta">
|
||||||
|
<span class="status <?= e($page['status']) ?>"><svg class="icon" aria-hidden="true"><use href="#icon-toggle-right"></use></svg> <?= e(t('admin.editor.status_' . $page['status'])) ?></span>
|
||||||
|
<a class="admin-list-view" href="<?= e($pageViewUrl) ?>" target="_blank" rel="noopener noreferrer" title="<?= e(t('admin.content.view_page')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg> <?= e(t('admin.content.view_page')) ?>
|
||||||
|
</a>
|
||||||
|
<?php if ($isHome): ?>
|
||||||
|
<div class="page-badge-wrapper">
|
||||||
|
<button type="button" class="page-badge home" aria-expanded="false" aria-controls="badge-popover-home-<?= e($pageSlug) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-globe"></use></svg> <?= e(t('admin.content.badge_home')) ?>
|
||||||
|
</button>
|
||||||
|
<div id="badge-popover-home-<?= e($pageSlug) ?>" class="page-badge-popover" hidden>
|
||||||
|
<div class="page-badge-popover-top">
|
||||||
|
<span class="page-badge-popover-label"><?= e(t('admin.content.badge_special_page_label')) ?></span>
|
||||||
|
<button type="button" class="page-badge-popover-close" aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="page-badge-popover-title"><?= e(t('admin.content.badge_home')) ?></div>
|
||||||
|
<p class="page-badge-popover-text">
|
||||||
|
<?= t('admin.content.badge_home_popover', [
|
||||||
|
'docs_link' => '<a href="https://docs.pureblog.org/special-pages/" target="_blank" rel="noopener noreferrer">' . e(t('admin.content.badge_docs_link')) . '</a>'
|
||||||
|
]) ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($isBlog): ?>
|
||||||
|
<div class="page-badge-wrapper">
|
||||||
|
<button type="button" class="page-badge blog" aria-expanded="false" aria-controls="badge-popover-blog-<?= e($pageSlug) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-notebook-pen"></use></svg> <?= e(t('admin.content.badge_blog')) ?>
|
||||||
|
</button>
|
||||||
|
<div id="badge-popover-blog-<?= e($pageSlug) ?>" class="page-badge-popover" hidden>
|
||||||
|
<div class="page-badge-popover-top">
|
||||||
|
<span class="page-badge-popover-label"><?= e(t('admin.content.badge_special_page_label')) ?></span>
|
||||||
|
<button type="button" class="page-badge-popover-close" aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="page-badge-popover-title"><?= e(t('admin.content.badge_blog')) ?></div>
|
||||||
|
<p class="page-badge-popover-text">
|
||||||
|
<?= t('admin.content.badge_blog_popover', [
|
||||||
|
'docs_link' => '<a href="https://docs.pureblog.org/special-pages/" target="_blank" rel="noopener noreferrer">' . e(t('admin.content.badge_docs_link')) . '</a>'
|
||||||
|
]) ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($isSearch): ?>
|
||||||
|
<div class="page-badge-wrapper">
|
||||||
|
<button type="button" class="page-badge search" aria-expanded="false" aria-controls="badge-popover-search-<?= e($pageSlug) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-search"></use></svg> <?= e(t('admin.content.badge_search')) ?>
|
||||||
|
</button>
|
||||||
|
<div id="badge-popover-search-<?= e($pageSlug) ?>" class="page-badge-popover" hidden>
|
||||||
|
<div class="page-badge-popover-top">
|
||||||
|
<span class="page-badge-popover-label"><?= e(t('admin.content.badge_special_page_label')) ?></span>
|
||||||
|
<button type="button" class="page-badge-popover-close" aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="page-badge-popover-title"><?= e(t('admin.content.badge_search')) ?></div>
|
||||||
|
<p class="page-badge-popover-text">
|
||||||
|
<?= t('admin.content.badge_search_popover', [
|
||||||
|
'docs_link' => '<a href="https://docs.pureblog.org/special-pages/" target="_blank" rel="noopener noreferrer">' . e(t('admin.content.badge_docs_link')) . '</a>'
|
||||||
|
]) ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
2978
admin/css/admin.css
Normal file
311
admin/dashboard.php
Normal file
|
|
@ -0,0 +1,311 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/../includes/updater.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
if (!$blogPostsEnabled) {
|
||||||
|
header('Location: ' . base_path() . '/admin/content.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$publishedPosts = array_values(array_filter(get_all_posts(true), static fn(array $post): bool => ($post['status'] ?? 'draft') === 'published'));
|
||||||
|
$publishedCount = count($publishedPosts);
|
||||||
|
$tz = site_timezone_object($config);
|
||||||
|
$now = new DateTimeImmutable('now', $tz);
|
||||||
|
$currentYear = (int) $now->format('Y');
|
||||||
|
|
||||||
|
$publishedThisYear = 0;
|
||||||
|
$totalWordsThisYear = 0;
|
||||||
|
$tagCounts = [];
|
||||||
|
$tagCountsThisYear = [];
|
||||||
|
$tagDisplayNames = [];
|
||||||
|
$totalWords = 0;
|
||||||
|
$allTimeMonthCounts = array_fill(1, 12, 0);
|
||||||
|
$allTimeDayCounts = array_fill(1, 7, 0); // 1=Mon … 7=Sun (ISO 8601)
|
||||||
|
$yearCounts = [];
|
||||||
|
|
||||||
|
// Build rolling 12-month chart slots (oldest first)
|
||||||
|
$chartMonths = [];
|
||||||
|
$firstOfMonth = new DateTimeImmutable($now->format('Y-m-01'), $tz);
|
||||||
|
for ($i = 11; $i >= 0; $i--) {
|
||||||
|
$dt = $firstOfMonth->modify("-{$i} months");
|
||||||
|
$month = (int) $dt->format('n');
|
||||||
|
$chartMonths[] = [
|
||||||
|
'year' => (int) $dt->format('Y'),
|
||||||
|
'month' => $month,
|
||||||
|
'label' => t('date.months_short.' . ($month - 1)),
|
||||||
|
'count' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$chartIndex = [];
|
||||||
|
foreach ($chartMonths as $idx => $cm) {
|
||||||
|
$chartIndex[$cm['year'] . '-' . $cm['month']] = $idx;
|
||||||
|
}
|
||||||
|
$recentCutoff = $firstOfMonth->modify('-11 months')->getTimestamp();
|
||||||
|
|
||||||
|
foreach ($publishedPosts as $post) {
|
||||||
|
$content = (string) ($post['content'] ?? '');
|
||||||
|
$totalWords += str_word_count($content);
|
||||||
|
|
||||||
|
$timestamp = (int) ($post['timestamp'] ?? 0);
|
||||||
|
if ($timestamp > 0) {
|
||||||
|
$dt = (new DateTimeImmutable('@' . $timestamp))->setTimezone($tz);
|
||||||
|
$postYear = (int) $dt->format('Y');
|
||||||
|
$postMon = (int) $dt->format('n');
|
||||||
|
$postDay = (int) $dt->format('N'); // 1=Mon … 7=Sun
|
||||||
|
|
||||||
|
$chartKey = $postYear . '-' . $postMon;
|
||||||
|
if (isset($chartIndex[$chartKey])) {
|
||||||
|
$chartMonths[$chartIndex[$chartKey]]['count']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($timestamp >= $recentCutoff) {
|
||||||
|
$publishedThisYear++;
|
||||||
|
$totalWordsThisYear += str_word_count($content);
|
||||||
|
}
|
||||||
|
|
||||||
|
$allTimeMonthCounts[$postMon]++;
|
||||||
|
$allTimeDayCounts[$postDay]++;
|
||||||
|
$yearCounts[$postYear] = ($yearCounts[$postYear] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags = $post['tags'] ?? [];
|
||||||
|
if (!is_array($tags)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$name = trim((string) $tag);
|
||||||
|
if ($name !== '') {
|
||||||
|
$slug = normalize_tag($name);
|
||||||
|
if ($slug === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$tagDisplayNames[$slug] ??= $name;
|
||||||
|
$tagCounts[$slug] = ($tagCounts[$slug] ?? 0) + 1;
|
||||||
|
if ($timestamp >= $recentCutoff) {
|
||||||
|
$tagCountsThisYear[$slug] = ($tagCountsThisYear[$slug] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($yearCounts);
|
||||||
|
$maxYearCount = !empty($yearCounts) ? max($yearCounts) : 1;
|
||||||
|
|
||||||
|
$avgWordsAllTime = $publishedCount > 0 ? (int) round($totalWords / $publishedCount) : 0;
|
||||||
|
$avgWordsThisYear = $publishedThisYear > 0 ? (int) round($totalWordsThisYear / $publishedThisYear) : 0;
|
||||||
|
$booksEquivalent = $totalWords > 0 ? round($totalWords / 80000, 1) : 0;
|
||||||
|
$booksThisYear = $totalWordsThisYear > 0 ? round($totalWordsThisYear / 80000, 1) : 0;
|
||||||
|
|
||||||
|
// Last published time
|
||||||
|
$lastTimestamp = 0;
|
||||||
|
foreach ($publishedPosts as $post) {
|
||||||
|
$ts = (int) ($post['timestamp'] ?? 0);
|
||||||
|
if ($ts > $lastTimestamp) {
|
||||||
|
$lastTimestamp = $ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$lastPublishedAgo = $lastTimestamp > 0 ? relative_time($lastTimestamp) : t('admin.dashboard.no_posts_yet');
|
||||||
|
|
||||||
|
$maxChartCount = max(1, ...array_column($chartMonths, 'count'));
|
||||||
|
$maxMonthCount = max(1, max($allTimeMonthCounts));
|
||||||
|
$maxDayCount = max(1, max($allTimeDayCounts));
|
||||||
|
|
||||||
|
uasort($tagCounts, static fn(int $a, int $b): int => $b <=> $a);
|
||||||
|
uasort($tagCountsThisYear, static fn(int $a, int $b): int => $b <=> $a);
|
||||||
|
|
||||||
|
$topTagEntries = [];
|
||||||
|
$n = 0;
|
||||||
|
foreach ($tagCounts as $tag => $count) {
|
||||||
|
$topTagEntries[] = '<a href="' . base_path() . '/admin/content.php?tab=posts&tag=' . urlencode((string) $tag) . '"><strong>' . e($tagDisplayNames[$tag] ?? (string) $tag) . '</strong></a> (' . (int) $count . ')';
|
||||||
|
if (++$n >= 5) break;
|
||||||
|
}
|
||||||
|
$topTagsLabel = $topTagEntries ? implode(', ', $topTagEntries) : t('admin.dashboard.stat_no_tags');
|
||||||
|
|
||||||
|
$topTagEntriesThisYear = [];
|
||||||
|
$n = 0;
|
||||||
|
foreach ($tagCountsThisYear as $tag => $count) {
|
||||||
|
$topTagEntriesThisYear[] = '<a href="' . base_path() . '/admin/content.php?tab=posts&tag=' . urlencode((string) $tag) . '&since=' . $recentCutoff . '"><strong>' . e($tagDisplayNames[$tag] ?? (string) $tag) . '</strong></a> (' . (int) $count . ')';
|
||||||
|
if (++$n >= 5) break;
|
||||||
|
}
|
||||||
|
$topTagsThisYearLabel = $topTagEntriesThisYear ? implode(', ', $topTagEntriesThisYear) : t('admin.dashboard.stat_no_tags');
|
||||||
|
|
||||||
|
// Month labels for all-time chart
|
||||||
|
$monthLabels = [];
|
||||||
|
for ($m = 1; $m <= 12; $m++) {
|
||||||
|
$monthLabels[$m] = t('date.months_short.' . ($m - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Day labels for all-time chart (1=Mon … 7=Sun → days_short index $d % 7)
|
||||||
|
$dayLabels = [];
|
||||||
|
for ($d = 1; $d <= 7; $d++) {
|
||||||
|
$dayLabels[$d] = t('date.days_short.' . ($d % 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version check — cached for 6 hours to avoid a GitHub API call on every load
|
||||||
|
$currentVersion = detect_current_pureblog_version();
|
||||||
|
$versionCacheFile = PUREBLOG_BASE_PATH . '/content/.version-cache';
|
||||||
|
$latestVersion = '';
|
||||||
|
$cacheAge = is_file($versionCacheFile) ? (time() - (int) @filemtime($versionCacheFile)) : PHP_INT_MAX;
|
||||||
|
if ($cacheAge > 21600) {
|
||||||
|
$release = fetch_latest_pureblog_release();
|
||||||
|
if ($release['ok'] && $release['tag'] !== '') {
|
||||||
|
$latestVersion = $release['tag'];
|
||||||
|
@file_put_contents($versionCacheFile, $latestVersion);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$cached = @file_get_contents($versionCacheFile);
|
||||||
|
$latestVersion = is_string($cached) ? trim($cached) : '';
|
||||||
|
}
|
||||||
|
$updateAvailable = $latestVersion !== '' && $currentVersion !== 'unknown' && version_compare(ltrim($currentVersion, 'vV'), ltrim($latestVersion, 'vV'), '<');
|
||||||
|
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
$adminTitle = t('admin.dashboard.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.nav.dashboard')) ?></h1>
|
||||||
|
|
||||||
|
<!-- Top row: snapshot -->
|
||||||
|
<div class="dashboard-stats-3">
|
||||||
|
<?php if ($currentVersion !== 'unknown'): ?>
|
||||||
|
<div class="dashboard-stat-card dashboard-version-card">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.version_label')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e($currentVersion) ?></p>
|
||||||
|
<?php if ($updateAvailable): ?>
|
||||||
|
<a class="dashboard-version-update" href="<?= base_path() ?>/admin/settings-updates.php"><?= e(t('admin.dashboard.version_update_link', ['latest' => $latestVersion])) ?></a>
|
||||||
|
<?php elseif ($latestVersion !== ''): ?>
|
||||||
|
<p class="dashboard-version-uptodate"><?= e(t('admin.dashboard.version_uptodate')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="dashboard-stat-card"></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.last_published')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e($lastPublishedAgo) ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_published')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e(number_format($publishedCount)) ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- This year -->
|
||||||
|
<h2 class="dashboard-h2"><?= e(t('admin.dashboard.section_this_year', ['year' => $currentYear])) ?></h2>
|
||||||
|
|
||||||
|
<?php $chartTotal = array_sum(array_column($chartMonths, 'count')); ?>
|
||||||
|
<?php if ($chartTotal > 0): ?>
|
||||||
|
<div class="dashboard-chart dashboard-chart-full" aria-label="<?= e(t('admin.dashboard.chart_title')) ?>">
|
||||||
|
<?php foreach ($chartMonths as $cm): ?>
|
||||||
|
<?php $barPx = $cm['count'] > 0 ? max(3, (int) round(($cm['count'] / $maxChartCount) * 120)) : 0; ?>
|
||||||
|
<?php $colUrl = base_path() . '/admin/content.php?tab=posts&year=' . $cm['year'] . '&month=' . $cm['month']; ?>
|
||||||
|
<?php if ($cm['count'] > 0): ?>
|
||||||
|
<a class="dashboard-chart-col" href="<?= e($colUrl) ?>">
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="dashboard-chart-col">
|
||||||
|
<?php endif; ?>
|
||||||
|
<span class="dashboard-chart-count"><?= $cm['count'] > 0 ? $cm['count'] : '' ?></span>
|
||||||
|
<div class="dashboard-chart-bar" style="height: <?= $barPx ?>px"></div>
|
||||||
|
<span class="dashboard-chart-label"><?= e($cm['label']) ?></span>
|
||||||
|
<?php if ($cm['count'] > 0): ?>
|
||||||
|
</a>
|
||||||
|
<?php else: ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="dashboard-stats-3">
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_this_year')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e((string) $publishedThisYear) ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_words_this_year')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e(number_format($totalWordsThisYear)) ?><?php if ($booksThisYear > 0): ?><br><span class="dashboard-stat-books">(<?= e(number_format($booksThisYear, 1)) ?> <?= e(t('admin.dashboard.stat_books')) ?>)</span><?php endif; ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-tags">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_top_tags')) ?></p>
|
||||||
|
<p class="dashboard-stat-value dashboard-stat-tags"><?= $topTagsThisYearLabel ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- All time -->
|
||||||
|
<h2 class="dashboard-h2"><?= e(t('admin.dashboard.section_all_time')) ?></h2>
|
||||||
|
|
||||||
|
<?php if (!empty($yearCounts)): ?>
|
||||||
|
<div class="dashboard-chart dashboard-chart-full" aria-label="<?= e(t('admin.dashboard.chart_all_years')) ?>">
|
||||||
|
<?php foreach ($yearCounts as $year => $count): ?>
|
||||||
|
<?php $barPx = $count > 0 ? max(3, (int) round(($count / $maxYearCount) * 120)) : 0; ?>
|
||||||
|
<a class="dashboard-chart-col" href="<?= e(base_path() . '/admin/content.php?tab=posts&year=' . $year) ?>">
|
||||||
|
<span class="dashboard-chart-count"><?= $count ?></span>
|
||||||
|
<div class="dashboard-chart-bar" style="height: <?= $barPx ?>px"></div>
|
||||||
|
<span class="dashboard-chart-label"><?= e((string) $year) ?></span>
|
||||||
|
</a>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="dashboard-stats-3">
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_total_words')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e(number_format($totalWords)) ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_books')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e(number_format($booksEquivalent, 1)) ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-stat-card dashboard-stat-card-metric">
|
||||||
|
<p class="dashboard-stat-label"><?= e(t('admin.dashboard.stat_avg_words')) ?></p>
|
||||||
|
<p class="dashboard-stat-value"><?= e(number_format($avgWordsAllTime)) ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="dashboard-chart-pair">
|
||||||
|
<div class="dashboard-chart-section">
|
||||||
|
<h3 class="dashboard-h3"><?= e(t('admin.dashboard.chart_all_months')) ?></h3>
|
||||||
|
<div class="dashboard-chart" aria-label="<?= e(t('admin.dashboard.chart_all_months')) ?>">
|
||||||
|
<?php for ($m = 1; $m <= 12; $m++): ?>
|
||||||
|
<?php $barPx = $allTimeMonthCounts[$m] > 0 ? max(3, (int) round(($allTimeMonthCounts[$m] / $maxMonthCount) * 100)) : 0; ?>
|
||||||
|
<div class="dashboard-chart-col">
|
||||||
|
<span class="dashboard-chart-count"><?= $allTimeMonthCounts[$m] > 0 ? $allTimeMonthCounts[$m] : '' ?></span>
|
||||||
|
<div class="dashboard-chart-bar" style="height: <?= $barPx ?>px"></div>
|
||||||
|
<span class="dashboard-chart-label"><?= e($monthLabels[$m]) ?></span>
|
||||||
|
</div>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-chart-section">
|
||||||
|
<h3 class="dashboard-h3"><?= e(t('admin.dashboard.chart_all_days')) ?></h3>
|
||||||
|
<div class="dashboard-chart" aria-label="<?= e(t('admin.dashboard.chart_all_days')) ?>">
|
||||||
|
<?php for ($d = 1; $d <= 7; $d++): ?>
|
||||||
|
<?php $barPx = $allTimeDayCounts[$d] > 0 ? max(3, (int) round(($allTimeDayCounts[$d] / $maxDayCount) * 100)) : 0; ?>
|
||||||
|
<div class="dashboard-chart-col">
|
||||||
|
<span class="dashboard-chart-count"><?= $allTimeDayCounts[$d] > 0 ? $allTimeDayCounts[$d] : '' ?></span>
|
||||||
|
<div class="dashboard-chart-bar" style="height: <?= $barPx ?>px"></div>
|
||||||
|
<span class="dashboard-chart-label"><?= e($dayLabels[$d]) ?></span>
|
||||||
|
</div>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($tagCounts): ?>
|
||||||
|
<div class="dashboard-all-tags">
|
||||||
|
<h2 class="dashboard-h2"><?= e(t('admin.dashboard.all_tags')) ?></h2>
|
||||||
|
<ul class="dashboard-all-tags-list">
|
||||||
|
<?php foreach ($tagCounts as $tag => $count): ?>
|
||||||
|
<li><a href="<?= base_path() ?>/admin/content.php?tab=posts&tag=<?= urlencode((string) $tag) ?>"><?= e($tagDisplayNames[$tag] ?? (string) $tag) ?></a> <span class="dashboard-tag-count">(<?= (int) $count ?>)</span></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
67
admin/delete-content.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$type = trim(($_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET)['type'] ?? '');
|
||||||
|
if (!in_array($type, ['post', 'page'], true)) {
|
||||||
|
http_response_code(400);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = null;
|
||||||
|
$slug = '';
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$item = $slug !== '' ? ($type === 'post' ? get_post_by_slug($slug, true) : get_page_by_slug($slug, true)) : null;
|
||||||
|
if ($slug === '') {
|
||||||
|
$errors[] = t("admin.delete_{$type}.error_missing");
|
||||||
|
} elseif (!$item) {
|
||||||
|
$errors[] = t("admin.delete_{$type}.error_not_found");
|
||||||
|
} elseif (!($type === 'post' ? delete_post_by_slug($slug) : delete_page_by_slug($slug))) {
|
||||||
|
$errors[] = t("admin.delete_{$type}.error_delete");
|
||||||
|
} else {
|
||||||
|
header('Location: ' . base_path() . '/admin/content.php?tab=' . ($type === 'post' ? 'posts' : 'pages') . '&deleted=1');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$slug = trim($_GET['slug'] ?? '');
|
||||||
|
$item = $slug !== '' ? ($type === 'post' ? get_post_by_slug($slug, true) : get_page_by_slug($slug, true)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t("admin.delete_{$type}.page_title");
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main>
|
||||||
|
<h1><?= e(t("admin.delete_{$type}.heading")) ?></h1>
|
||||||
|
|
||||||
|
<?php if ($errors): ?>
|
||||||
|
<div class="notice delete">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?= e($error) ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!$item): ?>
|
||||||
|
<p><?= e(t("admin.delete_{$type}.already_deleted")) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<p><?= e(t("admin.delete_{$type}.confirm", ['title' => $item['title']])) ?></p>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="type" value="<?= e($type) ?>">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($item['slug']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" class="delete"><?= e(t("admin.delete_{$type}.submit")) ?></button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
62
admin/delete-image-library.php
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
verify_csrf();
|
||||||
|
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$filename = trim($_POST['filename'] ?? '');
|
||||||
|
$redirect = base_path() . '/admin/images.php';
|
||||||
|
|
||||||
|
if ($slug === '' || $filename === '') {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.editor.error_delete_missing_data')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseDir = realpath(__DIR__ . '/../content/images');
|
||||||
|
if ($baseDir === false) {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.editor.error_image_folder_missing')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_safe_image_slug($slug)) {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.editor.error_image_invalid_path')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$targetDir = $baseDir . '/' . $slug;
|
||||||
|
$targetFile = $targetDir . '/' . basename($filename);
|
||||||
|
|
||||||
|
if (!validate_image_path($baseDir, $targetDir) || !validate_image_path($baseDir, $targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.editor.error_image_invalid_path')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_file($targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.editor.error_image_not_found')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unlink($targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '?delete_error=' . urlencode(t('admin.images.error_delete')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$thumbFile = $targetDir . '/thumbs/' . basename($filename);
|
||||||
|
if (is_file($thumbFile)) {
|
||||||
|
@unlink($thumbFile);
|
||||||
|
}
|
||||||
|
$thumbDir = $targetDir . '/thumbs';
|
||||||
|
if (is_dir($thumbDir) && !(glob($thumbDir . '/*') ?: [])) {
|
||||||
|
@rmdir($thumbDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining = glob($targetDir . '/*') ?: [];
|
||||||
|
if (!$remaining) {
|
||||||
|
@rmdir($targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ' . $redirect . '?deleted=1');
|
||||||
|
exit;
|
||||||
73
admin/delete-image.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
verify_csrf();
|
||||||
|
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$date = trim($_POST['date'] ?? '');
|
||||||
|
$filename = trim($_POST['filename'] ?? '');
|
||||||
|
$editorType = trim($_POST['editor_type'] ?? 'post');
|
||||||
|
|
||||||
|
$redirect = $editorType === 'page'
|
||||||
|
? base_path() . '/admin/edit-page.php?slug=' . urlencode($slug)
|
||||||
|
: base_path() . '/admin/edit-post.php?slug=' . urlencode($slug);
|
||||||
|
|
||||||
|
if ($slug === '' || ($editorType !== 'page' && $date === '') || $filename === '') {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_delete_missing_data')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$folderName = $slug;
|
||||||
|
$baseDir = realpath(__DIR__ . '/../content/images');
|
||||||
|
if ($baseDir === false) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_image_folder_missing')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_safe_image_slug($folderName)) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_image_invalid_path')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$targetDir = $baseDir . '/' . $folderName;
|
||||||
|
$targetFile = $targetDir . '/' . basename($filename);
|
||||||
|
|
||||||
|
if (!validate_image_path($baseDir, $targetDir)) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_image_invalid_path')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validate_image_path($baseDir, $targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_image_invalid_path')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_file($targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_image_not_found')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unlink($targetFile)) {
|
||||||
|
header('Location: ' . $redirect . '&upload_error=' . urlencode(t('admin.editor.error_delete_failed')));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$thumbFile = $targetDir . '/thumbs/' . basename($filename);
|
||||||
|
if (is_file($thumbFile)) {
|
||||||
|
@unlink($thumbFile);
|
||||||
|
}
|
||||||
|
$thumbDir = $targetDir . '/thumbs';
|
||||||
|
if (is_dir($thumbDir) && !(glob($thumbDir . '/*') ?: [])) {
|
||||||
|
@rmdir($thumbDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining = glob($targetDir . '/*') ?: [];
|
||||||
|
if (!$remaining) {
|
||||||
|
@rmdir($targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ' . $redirect);
|
||||||
|
exit;
|
||||||
333
admin/edit-page.php
Normal file
|
|
@ -0,0 +1,333 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$action = $_GET['action'] ?? '';
|
||||||
|
$slugParam = trim($_GET['slug'] ?? '');
|
||||||
|
$isEditing = $slugParam !== '';
|
||||||
|
|
||||||
|
$page = [
|
||||||
|
'title' => '',
|
||||||
|
'slug' => '',
|
||||||
|
'status' => 'draft',
|
||||||
|
'description' => '',
|
||||||
|
'include_in_nav' => false,
|
||||||
|
'content' => '',
|
||||||
|
];
|
||||||
|
$images = [];
|
||||||
|
|
||||||
|
$originalSlug = '';
|
||||||
|
|
||||||
|
if ($isEditing) {
|
||||||
|
$existing = get_page_by_slug($slugParam, true);
|
||||||
|
if ($existing) {
|
||||||
|
$page = [
|
||||||
|
'title' => $existing['title'] ?? '',
|
||||||
|
'slug' => $existing['slug'] ?? '',
|
||||||
|
'status' => $existing['status'] ?? 'draft',
|
||||||
|
'description' => $existing['description'] ?? '',
|
||||||
|
'include_in_nav'=> $existing['include_in_nav'] ?? true,
|
||||||
|
'content' => $existing['content'] ?? '',
|
||||||
|
'feature_image' => $existing['feature_image'] ?? '',
|
||||||
|
];
|
||||||
|
$originalSlug = $existing['slug'] ?? '';
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.editor.error_not_found_page');
|
||||||
|
$isEditing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'new') {
|
||||||
|
$isEditing = false;
|
||||||
|
$originalSlug = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$autosaveData = null;
|
||||||
|
if ($isEditing && $originalSlug !== '') {
|
||||||
|
$autosavePath = PUREBLOG_BASE_PATH . '/content/autosaves/page-' . $originalSlug . '.json';
|
||||||
|
if (is_file($autosavePath)) {
|
||||||
|
$raw = file_get_contents($autosavePath);
|
||||||
|
$decoded = $raw !== false ? json_decode($raw, true) : null;
|
||||||
|
if (is_array($decoded)) {
|
||||||
|
if (($decoded['content'] ?? '') !== $page['content'] || ($decoded['title'] ?? '') !== $page['title']) {
|
||||||
|
$autosaveData = $decoded;
|
||||||
|
} else {
|
||||||
|
@unlink($autosavePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
$page['title'] = trim($_POST['title'] ?? '');
|
||||||
|
$page['slug'] = trim($_POST['slug'] ?? '');
|
||||||
|
$page['status'] = trim($_POST['status'] ?? 'draft');
|
||||||
|
$page['description'] = trim($_POST['description'] ?? '');
|
||||||
|
$includeChoice = $_POST['include_in_nav'] ?? 'yes';
|
||||||
|
$page['include_in_nav'] = $includeChoice === 'yes' || $includeChoice === '1';
|
||||||
|
$page['content'] = trim($_POST['content'] ?? '');
|
||||||
|
$page['feature_image'] = trim($_POST['feature_image'] ?? '');
|
||||||
|
$originalSlug = trim($_POST['original_slug'] ?? '');
|
||||||
|
$originalStatus = trim($_POST['original_status'] ?? '');
|
||||||
|
|
||||||
|
if ($page['title'] === '') {
|
||||||
|
$errors[] = t('admin.editor.error_title_required');
|
||||||
|
} elseif ($page['slug'] === '' && slugify($page['title']) === '') {
|
||||||
|
$errors[] = t('admin.editor.error_empty_slug');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($page['status'], ['draft', 'published'], true)) {
|
||||||
|
$errors[] = t('admin.editor.error_invalid_status');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
$saveError = '';
|
||||||
|
$saved = save_page(
|
||||||
|
$page,
|
||||||
|
$originalSlug === '' ? null : $originalSlug,
|
||||||
|
$originalStatus === '' ? null : $originalStatus,
|
||||||
|
$saveError
|
||||||
|
);
|
||||||
|
if ($saved) {
|
||||||
|
$redirectSlug = $page['slug'] === '' ? slugify($page['title']) : $page['slug'];
|
||||||
|
$autosaveDir = PUREBLOG_BASE_PATH . '/content/autosaves';
|
||||||
|
@unlink($autosaveDir . '/page-' . $originalSlug . '.json');
|
||||||
|
@unlink($autosaveDir . '/page-' . $redirectSlug . '.json');
|
||||||
|
if (!empty($_POST['ajax_save'])) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['saved' => true, 'slug' => $redirectSlug]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
header('Location: ' . base_path() . '/admin/edit-page.php?slug=' . urlencode($redirectSlug) . '&saved=1');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$errors[] = $saveError !== '' ? $saveError : t('admin.editor.error_save_page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['ajax_save'])) {
|
||||||
|
header('Content-Type: application/json', true, 422);
|
||||||
|
echo json_encode(['saved' => false, 'errors' => $errors]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageFolder = '';
|
||||||
|
if ($page['slug'] !== '') {
|
||||||
|
$imageFolder = __DIR__ . '/../content/images/' . $page['slug'];
|
||||||
|
if (is_dir($imageFolder)) {
|
||||||
|
$files = glob($imageFolder . '/*') ?: [];
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (is_file($file)) {
|
||||||
|
$basename = basename($file);
|
||||||
|
$altText = pathinfo($basename, PATHINFO_FILENAME) ?: 'image';
|
||||||
|
$url = base_path() . '/content/images/' . $page['slug'] . '/' . $basename;
|
||||||
|
$images[] = [
|
||||||
|
'filename' => $basename,
|
||||||
|
'markdown' => '',
|
||||||
|
'url' => $url,
|
||||||
|
'thumb_url' => get_image_thumb_url($page['slug'], $basename),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t($isEditing ? 'admin.page_editor.edit_title' : 'admin.page_editor.new_title');
|
||||||
|
$codeMirror = 'markdown';
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main>
|
||||||
|
<div class="editor-grid">
|
||||||
|
<section class="editor-main">
|
||||||
|
<h1><?= e(t('admin.page_editor.page_title')) ?></h1>
|
||||||
|
<?php if ($errors): ?>
|
||||||
|
<div class="notice delete">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?= e($error) ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['saved'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.editor.notice_saved_page')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['uploaded'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.editor.notice_image_uploaded')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['upload_error'])): ?>
|
||||||
|
<p class="notice delete" data-auto-dismiss><?= e($_GET['upload_error']) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form method="post" class="editor-form" id="page-form">
|
||||||
|
<input type="hidden" name="original_slug" value="<?= e($originalSlug) ?>">
|
||||||
|
<input type="hidden" name="original_status" value="<?= e($page['status']) ?>">
|
||||||
|
<input type="hidden" id="feature-image-value" name="feature_image" value="<?= e($page['feature_image'] ?? '') ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
|
<nav class="editor-actions">
|
||||||
|
<button class="save" type="submit" form="page-form" aria-label="<?= e(t('admin.page_editor.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.page_editor.save')) ?>
|
||||||
|
</button>
|
||||||
|
<button type="button" id="preview-button" aria-label="<?= e(t('admin.page_editor.preview')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg>
|
||||||
|
<?= e(t('admin.page_editor.preview')) ?>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<?php if ($isEditing && $page['slug'] !== ''): ?>
|
||||||
|
<button type="submit" form="delete-page-form" class="link-button delete" aria-label="<?= e(t('admin.page_editor.delete')) ?>" onclick="return confirm('<?= e(t('admin.page_editor.delete_confirm')) ?>');">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.page_editor.delete')) ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
<span id="autosave-status" class="autosave-status" aria-live="polite"></span>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<label for="title"><?= e(t('admin.editor.title_label')) ?></label>
|
||||||
|
<input type="text" id="title" name="title" value="<?= e($page['title']) ?>" required autocomplete="off">
|
||||||
|
|
||||||
|
<label for="content"><?= e(t('admin.editor.content_label')) ?> <span class="tip">(<a target="_blank" rel="noopener noreferrer" href="https://pureblog.org/markdown-helper"><?= e(t('admin.editor.tip_markdown')) ?></a>)</span></label>
|
||||||
|
<textarea id="content" name="content" rows="18" autocomplete="off"><?= e($page['content']) ?></textarea>
|
||||||
|
</form>
|
||||||
|
<?php if ($isEditing && $page['slug'] !== ''): ?>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-content.php" id="delete-page-form">
|
||||||
|
<input type="hidden" name="type" value="page">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($page['slug']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
<aside class="editor-sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<button type="button" class="sidebar-toggle" id="sidebar-toggle-tab" aria-label="<?= e(t('admin.page_editor.settings_title')) ?>" title="<?= e(t('admin.page_editor.settings_title')) ?>">
|
||||||
|
<svg class="icon close-icon" aria-hidden="true"><use href="#icon-panel-right-close"></use></svg>
|
||||||
|
<svg class="icon open-icon" aria-hidden="true"><use href="#icon-settings"></use></svg>
|
||||||
|
</button>
|
||||||
|
<span class="sidebar-title"><?= e(t('admin.page_editor.settings_title')) ?></span>
|
||||||
|
</div>
|
||||||
|
<section class="sidebar-section">
|
||||||
|
<div class="section-divider">
|
||||||
|
<label for="slug"><?= e(t('admin.editor.slug_label')) ?></label>
|
||||||
|
<input type="text" id="slug" name="slug" form="page-form" value="<?= e($page['slug']) ?>" autocomplete="off">
|
||||||
|
|
||||||
|
<label for="description"><?= e(t('admin.editor.description_label')) ?></label>
|
||||||
|
<textarea id="description" name="description" form="page-form" rows="3" autocomplete="off"><?= e($page['description']) ?></textarea>
|
||||||
|
|
||||||
|
<label for="status"><?= e(t('admin.editor.status_label')) ?></label>
|
||||||
|
<select id="status" name="status" form="page-form">
|
||||||
|
<option value="draft" <?= $page['status'] === 'draft' ? 'selected' : '' ?>><?= e(t('admin.editor.status_draft')) ?></option>
|
||||||
|
<option value="published" <?= $page['status'] === 'published' ? 'selected' : '' ?>><?= e(t('admin.editor.status_published')) ?></option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="include_in_nav"><?= e(t('admin.page_editor.nav_label')) ?></label>
|
||||||
|
<select id="include_in_nav" name="include_in_nav" form="page-form">
|
||||||
|
<option value="yes" <?= $page['include_in_nav'] ? 'selected' : '' ?>><?= e(t('admin.page_editor.nav_yes')) ?></option>
|
||||||
|
<option value="no" <?= !$page['include_in_nav'] ? 'selected' : '' ?>><?= e(t('admin.page_editor.nav_no')) ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="sidebar-section">
|
||||||
|
<div class="section-divider">
|
||||||
|
<span class="images-title"><?= e(t('admin.editor.images_title')) ?></span>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/upload-image.php" enctype="multipart/form-data" class="upload-form">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($page['slug']) ?>">
|
||||||
|
<input type="hidden" name="editor_type" value="page">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<label class="hidden" for="image"><?= e(t('admin.editor.upload_label')) ?></label>
|
||||||
|
<input type="file" id="image" name="image[]" accept="image/*,.avif" multiple>
|
||||||
|
<button type="submit" disabled>
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-upload"></use></svg>
|
||||||
|
<?= e(t('admin.editor.upload')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php if (!$images): ?>
|
||||||
|
<p><?= e(t('admin.editor.no_images')) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="attached-images-header">
|
||||||
|
<p><?= e(t('admin.editor.attached_images')) ?></p>
|
||||||
|
<button type="button" class="link-button insert-gallery-btn" title="<?= e(t('admin.editor.insert_gallery_title')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-image"></use></svg>
|
||||||
|
<?= e(t('admin.editor.insert_gallery')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<ul class="image-list">
|
||||||
|
<?php foreach ($images as $image):
|
||||||
|
$imageRawPath = '/content/images/' . $page['slug'] . '/' . $image['filename'];
|
||||||
|
$isFeature = ($page['feature_image'] ?? '') === $imageRawPath;
|
||||||
|
?>
|
||||||
|
<li<?= $isFeature ? ' class="is-feature"' : '' ?>>
|
||||||
|
<div class="image-list-top">
|
||||||
|
<img src="<?= e($image['thumb_url']) ?>" width="30" height="30" class="image-list-preview" alt="<?= e($image['filename']) ?>"/>
|
||||||
|
<code><?= e($image['filename']) ?></code>
|
||||||
|
</div>
|
||||||
|
<div class="image-list-actions">
|
||||||
|
<label class="feature-image-label">
|
||||||
|
<input type="checkbox" class="feature-image-check" data-url="<?= e($imageRawPath) ?>" data-filename="<?= e($image['filename']) ?>"<?= $isFeature ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.editor.feature_image')) ?>
|
||||||
|
</label>
|
||||||
|
<button type="button" class="link-button copy-markdown" data-markdown="<?= e($image['markdown']) ?>"><svg class="icon" aria-hidden="true"><use href="#icon-copy"></use></svg> <?= e(t('admin.editor.copy')) ?></button>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-image.php" class="inline-form" onsubmit="return confirm('<?= e(t('admin.page_editor.delete_image_confirm')) ?>');">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($page['slug']) ?>">
|
||||||
|
<input type="hidden" name="editor_type" value="page">
|
||||||
|
<input type="hidden" name="filename" value="<?= e($image['filename']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" class="link-button delete"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
window.PureblogEditorConfig = {
|
||||||
|
editorType: 'page',
|
||||||
|
formId: 'page-form',
|
||||||
|
csrfToken: '<?= e(csrf_token()) ?>',
|
||||||
|
basePath: '<?= e(base_path()) ?>',
|
||||||
|
autosave: <?= $autosaveData !== null ? json_encode($autosaveData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) : 'null' ?>,
|
||||||
|
strings: <?= json_encode([
|
||||||
|
'autosaving' => t('admin.editor.js_autosaving'),
|
||||||
|
'autosaved' => t('admin.editor.js_autosaved'),
|
||||||
|
'autosave_failed' => t('admin.editor.js_autosave_failed'),
|
||||||
|
'autosave_banner' => t('admin.editor.js_autosave_banner'),
|
||||||
|
'view' => t('admin.editor.js_view'),
|
||||||
|
'hide' => t('admin.editor.js_hide'),
|
||||||
|
'restore' => t('admin.editor.js_restore'),
|
||||||
|
'discard' => t('admin.editor.js_discard'),
|
||||||
|
'title_label' => t('admin.editor.js_title_label'),
|
||||||
|
'save_failed' => t('admin.editor.js_save_failed'),
|
||||||
|
'save_before_upload'=> t('admin.editor.js_save_before_upload'),
|
||||||
|
'copied' => t('admin.editor.js_copied'),
|
||||||
|
'copy' => t('admin.editor.copy'),
|
||||||
|
'copy_failed' => t('admin.editor.js_copy_failed'),
|
||||||
|
'save_post_first' => t('admin.editor.js_save_post_first'),
|
||||||
|
'save_page_first' => t('admin.editor.js_save_page_first'),
|
||||||
|
'upload_failed' => t('admin.editor.js_upload_failed'),
|
||||||
|
'feature_image_confirm' => t('admin.editor.js_feature_image_confirm'),
|
||||||
|
'feature_image_failed' => t('admin.editor.js_feature_image_failed'),
|
||||||
|
'insert_gallery' => t('admin.editor.insert_gallery'),
|
||||||
|
'gallery_inserted' => t('admin.editor.js_gallery_inserted'),
|
||||||
|
'gallery_picker_title' => t('admin.editor.gallery_picker_title'),
|
||||||
|
'gallery_picker_select_all' => t('admin.editor.gallery_picker_select_all'),
|
||||||
|
'gallery_picker_deselect_all' => t('admin.editor.gallery_picker_deselect_all'),
|
||||||
|
'gallery_picker_insert' => t('admin.editor.gallery_picker_insert'),
|
||||||
|
'gallery_picker_cancel' => t('admin.editor.gallery_picker_cancel'),
|
||||||
|
'gallery_picker_count' => t('admin.editor.gallery_picker_count'),
|
||||||
|
'gallery_picker_no_selected' => t('admin.editor.gallery_picker_no_selected'),
|
||||||
|
], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE) ?>,
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script type="module" src="<?= base_path() ?>/admin/js/editor.js?v=<?= e((string) @filemtime(__DIR__ . '/js/editor.js')) ?>"></script>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
659
admin/edit-post.php
Normal file
|
|
@ -0,0 +1,659 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
if (!$blogPostsEnabled) {
|
||||||
|
header('Location: ' . base_path() . '/admin/content.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$images = [];
|
||||||
|
$action = $_GET['action'] ?? '';
|
||||||
|
$slugParam = trim($_GET['slug'] ?? '');
|
||||||
|
$isEditing = $slugParam !== '';
|
||||||
|
|
||||||
|
$post = [
|
||||||
|
'title' => '',
|
||||||
|
'slug' => '',
|
||||||
|
'date' => current_site_datetime_for_storage($config),
|
||||||
|
'status' => 'draft',
|
||||||
|
'tags' => [],
|
||||||
|
'description' => '',
|
||||||
|
'content' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
$originalSlug = '';
|
||||||
|
|
||||||
|
if ($isEditing) {
|
||||||
|
$existing = get_post_by_slug($slugParam, true);
|
||||||
|
if ($existing !== null && $existing !== false) {
|
||||||
|
$post = [
|
||||||
|
'title' => $existing['title'] ?? '',
|
||||||
|
'slug' => $existing['slug'] ?? '',
|
||||||
|
'date' => $existing['date'] ?? current_site_datetime_for_storage($config),
|
||||||
|
'status' => $existing['status'] ?? 'draft',
|
||||||
|
'tags' => $existing['tags'] ?? [],
|
||||||
|
'description' => $existing['description'] ?? '',
|
||||||
|
'content' => $existing['content'] ?? '',
|
||||||
|
'layout' => $existing['layout'] ?? '',
|
||||||
|
'feature_image' => $existing['feature_image'] ?? '',
|
||||||
|
];
|
||||||
|
$originalSlug = $existing['slug'] ?? '';
|
||||||
|
$originalExisting = $existing;
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.editor.error_not_found_post');
|
||||||
|
$isEditing = false;
|
||||||
|
$originalExisting = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$originalExisting = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'new') {
|
||||||
|
$isEditing = false;
|
||||||
|
$originalSlug = '';
|
||||||
|
$post['layout'] = trim($_GET['layout'] ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$autosaveData = null;
|
||||||
|
if ($isEditing && $originalSlug !== '') {
|
||||||
|
$autosavePath = PUREBLOG_BASE_PATH . '/content/autosaves/post-' . $originalSlug . '.json';
|
||||||
|
if (is_file($autosavePath)) {
|
||||||
|
$raw = file_get_contents($autosavePath);
|
||||||
|
$decoded = $raw !== false ? json_decode($raw, true) : null;
|
||||||
|
if (is_array($decoded)) {
|
||||||
|
if (($decoded['content'] ?? '') !== $post['content'] || ($decoded['title'] ?? '') !== $post['title']) {
|
||||||
|
$autosaveData = $decoded;
|
||||||
|
} else {
|
||||||
|
@unlink($autosavePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
$post['title'] = trim($_POST['title'] ?? '');
|
||||||
|
$post['slug'] = trim($_POST['slug'] ?? '');
|
||||||
|
$post['date'] = trim($_POST['date'] ?? '');
|
||||||
|
$post['status'] = trim($_POST['status'] ?? 'draft');
|
||||||
|
$post['content'] = trim($_POST['content'] ?? '');
|
||||||
|
$post['description'] = trim($_POST['description'] ?? '');
|
||||||
|
$post['layout'] = trim($_POST['post_layout'] ?? '');
|
||||||
|
$post['feature_image'] = trim($_POST['feature_image'] ?? '');
|
||||||
|
$tagsInput = trim($_POST['tags'] ?? '');
|
||||||
|
$post['tags'] = $tagsInput === '' ? [] : array_values(array_filter(array_map('trim', explode(',', $tagsInput))));
|
||||||
|
$originalSlug = trim($_POST['original_slug'] ?? '');
|
||||||
|
$originalStatus = trim($_POST['original_status'] ?? '');
|
||||||
|
$originalDate = trim($_POST['original_date'] ?? '');
|
||||||
|
|
||||||
|
$post['layout_fields'] = [];
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if (str_starts_with($key, 'layout_field__')) {
|
||||||
|
$fieldName = substr($key, strlen('layout_field__'));
|
||||||
|
$post['layout_fields'][$fieldName] = trim((string) $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = apply_filter('on_filter_post', $post);
|
||||||
|
|
||||||
|
if ($post['title'] === '') {
|
||||||
|
$errors[] = t('admin.editor.error_title_required');
|
||||||
|
} elseif ($post['slug'] === '' && slugify($post['title']) === '') {
|
||||||
|
$errors[] = t('admin.editor.error_empty_slug');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($post['status'], ['draft', 'published', 'scheduled'], true)) {
|
||||||
|
$errors[] = t('admin.editor.error_invalid_status');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
if ($post['status'] === 'published' && $originalStatus !== 'published') {
|
||||||
|
$post['date'] = current_site_datetime_for_storage($config);
|
||||||
|
}
|
||||||
|
$saveError = '';
|
||||||
|
$saved = save_post(
|
||||||
|
$post,
|
||||||
|
$originalSlug === '' ? null : $originalSlug,
|
||||||
|
$originalDate === '' ? null : $originalDate,
|
||||||
|
$originalStatus === '' ? null : $originalStatus,
|
||||||
|
$saveError
|
||||||
|
);
|
||||||
|
if ($saved) {
|
||||||
|
$redirectSlug = $post['slug'] === '' ? slugify($post['title']) : $post['slug'];
|
||||||
|
$autosaveDir = PUREBLOG_BASE_PATH . '/content/autosaves';
|
||||||
|
@unlink($autosaveDir . '/post-' . $originalSlug . '.json');
|
||||||
|
@unlink($autosaveDir . '/post-' . $redirectSlug . '.json');
|
||||||
|
if (!empty($_POST['ajax_save'])) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['saved' => true, 'slug' => $redirectSlug, 'date' => $post['date']]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
header('Location: ' . base_path() . '/admin/edit-post.php?slug=' . urlencode($redirectSlug) . '&saved=1');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$errors[] = $saveError !== '' ? $saveError : t('admin.editor.error_save_post');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['ajax_save'])) {
|
||||||
|
header('Content-Type: application/json', true, 422);
|
||||||
|
echo json_encode(['saved' => false, 'errors' => $errors]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageFolder = '';
|
||||||
|
if ($post['slug'] !== '') {
|
||||||
|
$imageFolder = __DIR__ . '/../content/images/' . $post['slug'];
|
||||||
|
if (is_dir($imageFolder)) {
|
||||||
|
$files = glob($imageFolder . '/*') ?: [];
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (is_file($file)) {
|
||||||
|
$basename = basename($file);
|
||||||
|
$altText = pathinfo($basename, PATHINFO_FILENAME) ?: 'image';
|
||||||
|
$url = base_path() . '/content/images/' . $post['slug'] . '/' . $basename;
|
||||||
|
$images[] = [
|
||||||
|
'filename' => $basename,
|
||||||
|
'markdown' => '',
|
||||||
|
'url' => $url,
|
||||||
|
'thumb_url' => get_image_thumb_url($post['slug'], $basename),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$allLayouts = get_layouts();
|
||||||
|
$currentLayout = trim($post['layout'] ?? '');
|
||||||
|
$layoutDef = null;
|
||||||
|
foreach ($allLayouts as $l) {
|
||||||
|
if ($l['name'] === $currentLayout) {
|
||||||
|
$layoutDef = $l;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$layoutFields = $layoutDef ? ($layoutDef['fields'] ?? []) : [];
|
||||||
|
|
||||||
|
$hasCustomTitle = false;
|
||||||
|
$hasCustomContent = false;
|
||||||
|
if ($layoutFields) {
|
||||||
|
foreach ($layoutFields as $field) {
|
||||||
|
$name = (string) ($field['name'] ?? '');
|
||||||
|
if ($name === 'title') {
|
||||||
|
$hasCustomTitle = true;
|
||||||
|
} elseif ($name === 'content') {
|
||||||
|
$hasCustomContent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$adminTitle = t($isEditing ? 'admin.post_editor.edit_title' : 'admin.post_editor.new_title');
|
||||||
|
$codeMirror = 'markdown';
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main>
|
||||||
|
<div class="editor-grid">
|
||||||
|
<section class="editor-main">
|
||||||
|
<h1><?= e(t('admin.post_editor.page_title')) ?></h1>
|
||||||
|
<?php if ($errors): ?>
|
||||||
|
<div class="notice delete">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?= e($error) ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['saved'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.editor.notice_saved_post')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['uploaded'])): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.editor.notice_image_uploaded')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($_GET['upload_error'])): ?>
|
||||||
|
<p class="notice delete" data-auto-dismiss><?= e($_GET['upload_error']) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="post" class="editor-form" id="editor-form">
|
||||||
|
<input type="hidden" name="original_slug" value="<?= e($originalSlug) ?>">
|
||||||
|
<input type="hidden" name="original_status" value="<?= e($post['status']) ?>">
|
||||||
|
<input type="hidden" name="original_date" value="<?= e($post['date']) ?>">
|
||||||
|
<input type="hidden" name="post_layout" value="<?= e($currentLayout) ?>">
|
||||||
|
<input type="hidden" id="feature-image-value" name="feature_image" value="<?= e($post['feature_image'] ?? '') ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
|
<nav class="editor-actions">
|
||||||
|
<button class="save" type="submit" form="editor-form" aria-label="<?= e(t('admin.post_editor.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.post_editor.save')) ?>
|
||||||
|
</button>
|
||||||
|
<button type="button" id="preview-button" aria-label="<?= e(t('admin.post_editor.preview')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg>
|
||||||
|
<?= e(t('admin.post_editor.preview')) ?>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<?php if ($isEditing && $post['slug'] !== ''): ?>
|
||||||
|
<button type="submit" form="delete-post-form" class="link-button delete" aria-label="<?= e(t('admin.post_editor.delete')) ?>" onclick="return confirm('<?= e(t('admin.post_editor.delete_confirm')) ?>');">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.post_editor.delete')) ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
<span id="autosave-status" class="autosave-status" aria-live="polite"></span>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<?php if (!$hasCustomTitle): ?>
|
||||||
|
<label for="title"><?= e(t('admin.editor.title_label')) ?></label>
|
||||||
|
<input type="text" id="title" name="title" value="<?= e($post['title']) ?>" autocomplete="off">
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!$hasCustomContent): ?>
|
||||||
|
<label for="content"><?= e(t('admin.editor.content_label')) ?> <span class="tip">(<a target="_blank" rel="noopener noreferrer" href="https://pureblog.org/markdown-helper"><?= e(t('admin.editor.tip_markdown')) ?></a>)</span></label>
|
||||||
|
<textarea id="content" name="content" rows="18" autocomplete="off"><?= e($post['content']) ?></textarea>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($layoutFields): ?>
|
||||||
|
<?php foreach ($layoutFields as $field):
|
||||||
|
$fieldName = (string) ($field['name'] ?? '');
|
||||||
|
if ($fieldName === ''): continue; endif;
|
||||||
|
|
||||||
|
$fieldLabel = (string) ($field['label'] ?? $fieldName);
|
||||||
|
|
||||||
|
if ($fieldName === 'title') {
|
||||||
|
$fieldType = (string) ($field['type'] ?? 'text');
|
||||||
|
$fieldId = 'title';
|
||||||
|
$inputName = 'title';
|
||||||
|
$fieldValue = $post['title'];
|
||||||
|
} elseif ($fieldName === 'content') {
|
||||||
|
$fieldType = (string) ($field['type'] ?? 'markdown');
|
||||||
|
$fieldId = 'content';
|
||||||
|
$inputName = 'content';
|
||||||
|
$fieldValue = $post['content'];
|
||||||
|
} else {
|
||||||
|
$fieldType = (string) ($field['type'] ?? 'text');
|
||||||
|
$fieldId = 'layout_field_' . $fieldName;
|
||||||
|
$inputName = 'layout_field__' . $fieldName;
|
||||||
|
$fieldValue = (string) ($originalExisting[$fieldName] ?? $post['layout_fields'][$fieldName] ?? '');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<?php if ($fieldType !== 'checkbox'): ?>
|
||||||
|
<label for="<?= e($fieldId) ?>">
|
||||||
|
<?= e($fieldLabel) ?>
|
||||||
|
<?php if ($fieldName === 'content'): ?>
|
||||||
|
<span class="tip">(<a target="_blank" rel="noopener noreferrer" href="https://pureblog.org/markdown-helper"><?= e(t('admin.editor.tip_markdown')) ?></a>)</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</label>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($fieldType === 'markdown'): ?>
|
||||||
|
<?php if ($fieldName === 'content'): ?>
|
||||||
|
<textarea id="content" name="content" rows="18" autocomplete="off"><?= e($fieldValue) ?></textarea>
|
||||||
|
<?php else: ?>
|
||||||
|
<textarea id="<?= e($fieldId) ?>" name="<?= e($inputName) ?>" rows="8" data-layout-markdown autocomplete="off"><?= e($fieldValue) ?></textarea>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php elseif ($fieldType === 'select'): ?>
|
||||||
|
<?php $fieldOptions = is_array($field['options'] ?? null) ? $field['options'] : []; ?>
|
||||||
|
<select id="<?= e($fieldId) ?>" name="<?= e($inputName) ?>">
|
||||||
|
<option value=""></option>
|
||||||
|
<?php foreach ($fieldOptions as $opt):
|
||||||
|
$opt = (string) $opt;
|
||||||
|
?>
|
||||||
|
<option value="<?= e($opt) ?>" <?= $fieldValue === $opt ? 'selected' : '' ?>><?= e($opt) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<?php elseif ($fieldType === 'checkbox'): ?>
|
||||||
|
<input type="hidden" name="<?= e($inputName) ?>" value="">
|
||||||
|
<label class="checkbox-label">
|
||||||
|
<input type="checkbox" id="<?= e($fieldId) ?>" name="<?= e($inputName) ?>" value="1" <?= $fieldValue === '1' ? 'checked' : '' ?>>
|
||||||
|
<?= e($fieldLabel) ?>
|
||||||
|
</label>
|
||||||
|
<?php else: ?>
|
||||||
|
<input type="text" id="<?= e($fieldId) ?>" name="<?= e($inputName) ?>" value="<?= e($fieldValue) ?>" autocomplete="off">
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
<?php if ($isEditing && $post['slug'] !== ''): ?>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-content.php" id="delete-post-form">
|
||||||
|
<input type="hidden" name="type" value="post">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($post['slug']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
<aside class="editor-sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<button type="button" class="sidebar-toggle" id="sidebar-toggle-tab" aria-label="<?= e(t('admin.post_editor.settings_title')) ?>" title="<?= e(t('admin.post_editor.settings_title')) ?>">
|
||||||
|
<svg class="icon close-icon" aria-hidden="true"><use href="#icon-panel-right-close"></use></svg>
|
||||||
|
<svg class="icon open-icon" aria-hidden="true"><use href="#icon-settings"></use></svg>
|
||||||
|
</button>
|
||||||
|
<span class="sidebar-title"><?= e(t('admin.post_editor.settings_title')) ?></span>
|
||||||
|
</div>
|
||||||
|
<section class="sidebar-section">
|
||||||
|
<div class="section-divider">
|
||||||
|
<label for="slug"><?= e(t('admin.editor.slug_label')) ?></label>
|
||||||
|
<input type="text" id="slug" name="slug" form="editor-form" value="<?= e($post['slug']) ?>" autocomplete="off">
|
||||||
|
|
||||||
|
<label for="description"><?= e(t('admin.editor.description_label')) ?></label>
|
||||||
|
<textarea id="description" name="description" form="editor-form" rows="3" autocomplete="off"><?= e($post['description']) ?></textarea>
|
||||||
|
|
||||||
|
<label for="date"><?= e(t('admin.editor.date_label')) ?></label>
|
||||||
|
<input type="text" id="date" name="date" form="editor-form" value="<?= e($post['date']) ?>" autocomplete="off">
|
||||||
|
|
||||||
|
<label for="status"><?= e(t('admin.editor.status_label')) ?></label>
|
||||||
|
<select id="status" name="status" form="editor-form">
|
||||||
|
<option value="draft" <?= $post['status'] === 'draft' ? 'selected' : '' ?>><?= e(t('admin.editor.status_draft')) ?></option>
|
||||||
|
<option value="scheduled" <?= $post['status'] === 'scheduled' ? 'selected' : '' ?>><?= e(t('admin.editor.status_scheduled')) ?></option>
|
||||||
|
<option value="published" <?= $post['status'] === 'published' ? 'selected' : '' ?>><?= e(t('admin.editor.status_published')) ?></option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="tag-entry"><?= e(t('admin.post_editor.tags_label')) ?></label>
|
||||||
|
<div class="tag-input-wrap">
|
||||||
|
<div class="tag-entry-row">
|
||||||
|
<input type="text" id="tag-entry" placeholder="<?= e(t('admin.post_editor.add_tag_placeholder')) ?>" autocomplete="off">
|
||||||
|
<button type="button" id="tag-add-btn" class="button tag-add-btn"><?= e(t('admin.post_editor.add_tag')) ?></button>
|
||||||
|
<ul id="tag-suggestions" class="tag-suggestions" hidden></ul>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="tags" name="tags" form="editor-form" value="<?= e(implode(', ', $post['tags'])) ?>">
|
||||||
|
<div id="tag-badges" class="tag-badges" aria-live="polite"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="sidebar-section">
|
||||||
|
<div class="section-divider">
|
||||||
|
<span class="images-title"><?= e(t('admin.editor.images_title')) ?></span>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/upload-image.php" enctype="multipart/form-data" class="upload-form">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($post['slug']) ?>">
|
||||||
|
<input type="hidden" name="date" value="<?= e($post['date']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<label class="hidden" for="image"><?= e(t('admin.editor.upload_label')) ?></label>
|
||||||
|
<input type="file" id="image" name="image[]" accept="image/*,.avif" multiple>
|
||||||
|
<button type="submit" disabled>
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-upload"></use></svg>
|
||||||
|
<?= e(t('admin.editor.upload')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php if (!$images): ?>
|
||||||
|
<p><?= e(t('admin.editor.no_images')) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="attached-images-header">
|
||||||
|
<p><?= e(t('admin.editor.attached_images')) ?></p>
|
||||||
|
<button type="button" class="link-button insert-gallery-btn" title="<?= e(t('admin.editor.insert_gallery_title')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-image"></use></svg>
|
||||||
|
<?= e(t('admin.editor.insert_gallery')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<ul class="image-list">
|
||||||
|
<?php foreach ($images as $image):
|
||||||
|
$imageRawPath = '/content/images/' . $post['slug'] . '/' . $image['filename'];
|
||||||
|
$isFeature = ($post['feature_image'] ?? '') === $imageRawPath;
|
||||||
|
?>
|
||||||
|
<li<?= $isFeature ? ' class="is-feature"' : '' ?>>
|
||||||
|
<div class="image-list-top">
|
||||||
|
<img src="<?= e($image['thumb_url']) ?>" width="30" height="30" class="image-list-preview" alt="<?= e($image['filename']) ?>"/>
|
||||||
|
<code><?= e($image['filename']) ?></code>
|
||||||
|
</div>
|
||||||
|
<div class="image-list-actions">
|
||||||
|
<label class="feature-image-label">
|
||||||
|
<input type="checkbox" class="feature-image-check" data-url="<?= e($imageRawPath) ?>" data-filename="<?= e($image['filename']) ?>"<?= $isFeature ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.editor.feature_image')) ?>
|
||||||
|
</label>
|
||||||
|
<button type="button" class="link-button copy-markdown" data-markdown="<?= e($image['markdown']) ?>"><svg class="icon" aria-hidden="true"><use href="#icon-copy"></use></svg> <?= e(t('admin.editor.copy')) ?></button>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-image.php" class="inline-form" onsubmit="return confirm('<?= e(t('admin.post_editor.delete_image_confirm')) ?>');">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($post['slug']) ?>">
|
||||||
|
<input type="hidden" name="date" value="<?= e($post['date']) ?>">
|
||||||
|
<input type="hidden" name="filename" value="<?= e($image['filename']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" class="link-button delete"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
window.PureblogEditorConfig = {
|
||||||
|
editorType: 'post',
|
||||||
|
formId: 'editor-form',
|
||||||
|
csrfToken: '<?= e(csrf_token()) ?>',
|
||||||
|
basePath: '<?= e(base_path()) ?>',
|
||||||
|
autosave: <?= $autosaveData !== null ? json_encode($autosaveData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) : 'null' ?>,
|
||||||
|
strings: <?= json_encode([
|
||||||
|
'autosaving' => t('admin.editor.js_autosaving'),
|
||||||
|
'autosaved' => t('admin.editor.js_autosaved'),
|
||||||
|
'autosave_failed' => t('admin.editor.js_autosave_failed'),
|
||||||
|
'autosave_banner' => t('admin.editor.js_autosave_banner'),
|
||||||
|
'view' => t('admin.editor.js_view'),
|
||||||
|
'hide' => t('admin.editor.js_hide'),
|
||||||
|
'restore' => t('admin.editor.js_restore'),
|
||||||
|
'discard' => t('admin.editor.js_discard'),
|
||||||
|
'title_label' => t('admin.editor.js_title_label'),
|
||||||
|
'save_failed' => t('admin.editor.js_save_failed'),
|
||||||
|
'save_before_upload'=> t('admin.editor.js_save_before_upload'),
|
||||||
|
'copied' => t('admin.editor.js_copied'),
|
||||||
|
'copy' => t('admin.editor.copy'),
|
||||||
|
'copy_failed' => t('admin.editor.js_copy_failed'),
|
||||||
|
'save_post_first' => t('admin.editor.js_save_post_first'),
|
||||||
|
'save_page_first' => t('admin.editor.js_save_page_first'),
|
||||||
|
'upload_failed' => t('admin.editor.js_upload_failed'),
|
||||||
|
'feature_image_confirm' => t('admin.editor.js_feature_image_confirm'),
|
||||||
|
'feature_image_failed' => t('admin.editor.js_feature_image_failed'),
|
||||||
|
'insert_gallery' => t('admin.editor.insert_gallery'),
|
||||||
|
'gallery_inserted' => t('admin.editor.js_gallery_inserted'),
|
||||||
|
'gallery_picker_title' => t('admin.editor.gallery_picker_title'),
|
||||||
|
'gallery_picker_select_all' => t('admin.editor.gallery_picker_select_all'),
|
||||||
|
'gallery_picker_deselect_all' => t('admin.editor.gallery_picker_deselect_all'),
|
||||||
|
'gallery_picker_insert' => t('admin.editor.gallery_picker_insert'),
|
||||||
|
'gallery_picker_cancel' => t('admin.editor.gallery_picker_cancel'),
|
||||||
|
'gallery_picker_count' => t('admin.editor.gallery_picker_count'),
|
||||||
|
'gallery_picker_no_selected' => t('admin.editor.gallery_picker_no_selected'),
|
||||||
|
], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE) ?>,
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script type="module" src="<?= base_path() ?>/admin/js/editor.js?v=<?= e((string) @filemtime(__DIR__ . '/js/editor.js')) ?>"></script>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const hiddenInput = document.getElementById('tags');
|
||||||
|
const entryInput = document.getElementById('tag-entry');
|
||||||
|
const addBtn = document.getElementById('tag-add-btn');
|
||||||
|
const badgesWrap = document.getElementById('tag-badges');
|
||||||
|
const list = document.getElementById('tag-suggestions');
|
||||||
|
if (!hiddenInput || !entryInput || !badgesWrap || !list) return;
|
||||||
|
|
||||||
|
let allTags = [];
|
||||||
|
let activeIndex = -1;
|
||||||
|
|
||||||
|
function parseTags(val) {
|
||||||
|
if (!val || typeof val !== 'string') return [];
|
||||||
|
return val
|
||||||
|
.split(',')
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tags = parseTags(hiddenInput.value);
|
||||||
|
|
||||||
|
fetch(window.PureblogEditorConfig.basePath + '/content/tag-index.json?v=<?= e((string) (@filemtime(PUREBLOG_BASE_PATH . '/content/tag-index.json') ?: PUREBLOG_VERSION)) ?>')
|
||||||
|
.then(r => r.ok ? r.json() : null)
|
||||||
|
.then(data => { if (data) allTags = Object.values(data).map(v => v.name); })
|
||||||
|
.catch(() => {});
|
||||||
|
|
||||||
|
function syncTags() {
|
||||||
|
hiddenInput.value = tags.join(', ');
|
||||||
|
hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
renderBadges();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBadges() {
|
||||||
|
badgesWrap.innerHTML = '';
|
||||||
|
tags.forEach((tag, idx) => {
|
||||||
|
const badge = document.createElement('span');
|
||||||
|
badge.className = 'tag-badge';
|
||||||
|
|
||||||
|
const label = document.createElement('span');
|
||||||
|
label.className = 'tag-badge-text';
|
||||||
|
label.textContent = tag;
|
||||||
|
|
||||||
|
const removeBtn = document.createElement('button');
|
||||||
|
removeBtn.type = 'button';
|
||||||
|
removeBtn.className = 'tag-badge-remove';
|
||||||
|
removeBtn.innerHTML = '×';
|
||||||
|
removeBtn.setAttribute('aria-label', '<?= e(t('admin.post_editor.remove_tag')) ?>: ' + tag);
|
||||||
|
removeBtn.title = '<?= e(t('admin.post_editor.remove_tag')) ?>';
|
||||||
|
removeBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
removeTag(idx);
|
||||||
|
});
|
||||||
|
|
||||||
|
badge.appendChild(label);
|
||||||
|
badge.appendChild(removeBtn);
|
||||||
|
badgesWrap.appendChild(badge);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTag(raw) {
|
||||||
|
if (!raw) return;
|
||||||
|
const pieces = raw.split(',').map(s => s.trim()).filter(Boolean);
|
||||||
|
let added = false;
|
||||||
|
pieces.forEach(item => {
|
||||||
|
const lower = item.toLowerCase();
|
||||||
|
const exists = tags.some(t => t.toLowerCase() === lower);
|
||||||
|
if (!exists) {
|
||||||
|
tags.push(item);
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (added) {
|
||||||
|
syncTags();
|
||||||
|
}
|
||||||
|
entryInput.value = '';
|
||||||
|
hideSuggestions();
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeTag(index) {
|
||||||
|
if (index >= 0 && index < tags.length) {
|
||||||
|
tags.splice(index, 1);
|
||||||
|
syncTags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideSuggestions() {
|
||||||
|
list.hidden = true;
|
||||||
|
list.innerHTML = '';
|
||||||
|
activeIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setActive(index) {
|
||||||
|
const items = list.querySelectorAll('li');
|
||||||
|
items.forEach(li => li.classList.remove('active'));
|
||||||
|
activeIndex = Math.max(-1, Math.min(index, items.length - 1));
|
||||||
|
if (activeIndex >= 0) items[activeIndex].classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSuggestions() {
|
||||||
|
const token = entryInput.value.trim().toLowerCase();
|
||||||
|
list.innerHTML = '';
|
||||||
|
activeIndex = -1;
|
||||||
|
|
||||||
|
if (token.length === 0) {
|
||||||
|
hideSuggestions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingLower = tags.map(t => t.toLowerCase());
|
||||||
|
const matches = allTags
|
||||||
|
.filter(t => t.toLowerCase().startsWith(token) && !existingLower.includes(t.toLowerCase()))
|
||||||
|
.slice(0, 10);
|
||||||
|
|
||||||
|
if (matches.length === 0) {
|
||||||
|
hideSuggestions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
matches.forEach(tag => {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
li.textContent = tag;
|
||||||
|
li.dataset.tag = tag;
|
||||||
|
li.addEventListener('mousedown', e => {
|
||||||
|
e.preventDefault();
|
||||||
|
addTag(tag);
|
||||||
|
entryInput.focus();
|
||||||
|
});
|
||||||
|
list.appendChild(li);
|
||||||
|
});
|
||||||
|
|
||||||
|
list.hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
entryInput.addEventListener('input', function () {
|
||||||
|
const val = entryInput.value;
|
||||||
|
if (val.includes(',')) {
|
||||||
|
addTag(val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showSuggestions();
|
||||||
|
});
|
||||||
|
|
||||||
|
entryInput.addEventListener('keydown', function (e) {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!list.hidden && activeIndex >= 0) {
|
||||||
|
const items = list.querySelectorAll('li');
|
||||||
|
if (items[activeIndex]) {
|
||||||
|
addTag(items[activeIndex].dataset.tag);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addTag(entryInput.value);
|
||||||
|
} else if (e.key === 'Tab' && !list.hidden && activeIndex >= 0) {
|
||||||
|
const items = list.querySelectorAll('li');
|
||||||
|
if (items[activeIndex]) {
|
||||||
|
e.preventDefault();
|
||||||
|
addTag(items[activeIndex].dataset.tag);
|
||||||
|
}
|
||||||
|
} else if (e.key === 'Backspace' && entryInput.value === '' && tags.length > 0) {
|
||||||
|
removeTag(tags.length - 1);
|
||||||
|
} else if (e.key === 'ArrowDown' && !list.hidden) {
|
||||||
|
e.preventDefault();
|
||||||
|
setActive(activeIndex + 1);
|
||||||
|
} else if (e.key === 'ArrowUp' && !list.hidden) {
|
||||||
|
e.preventDefault();
|
||||||
|
setActive(activeIndex - 1);
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
hideSuggestions();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addBtn?.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
addTag(entryInput.value);
|
||||||
|
entryInput.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
hiddenInput.addEventListener('change', function () {
|
||||||
|
tags = parseTags(hiddenInput.value);
|
||||||
|
renderBadges();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('click', e => {
|
||||||
|
if (!entryInput.contains(e.target) && !list.contains(e.target)) {
|
||||||
|
hideSuggestions();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
renderBadges();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
14
admin/icons/arrow-left.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="m12 19-7-7 7-7" />
|
||||||
|
<path d="M19 12H5" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 262 B |
1
admin/icons/braces.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-braces-icon lucide-braces"><path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"/><path d="M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1"/></svg>
|
||||||
|
After Width: | Height: | Size: 399 B |
1
admin/icons/calendar.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar-icon lucide-calendar"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>
|
||||||
|
After Width: | Height: | Size: 345 B |
14
admin/icons/circle-check.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<circle cx="12" cy="12" r="10" />
|
||||||
|
<path d="m9 12 2 2 4-4" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 273 B |
1
admin/icons/circle-gauge.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-gauge-icon lucide-circle-gauge"><path d="M15.6 2.7a10 10 0 1 0 5.7 5.7"/><circle cx="12" cy="12" r="2"/><path d="M13.4 10.6 19 5"/></svg>
|
||||||
|
After Width: | Height: | Size: 346 B |
15
admin/icons/circle-x.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<circle cx="12" cy="12" r="10" />
|
||||||
|
<path d="m15 9-6 6" />
|
||||||
|
<path d="m9 9 6 6" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 293 B |
14
admin/icons/copy.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
|
||||||
|
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 339 B |
16
admin/icons/download.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M12 15V3" />
|
||||||
|
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||||
|
<path d="m7 10 5 5 5-5" />
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
After Width: | Height: | Size: 319 B |
14
admin/icons/eye.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" />
|
||||||
|
<circle cx="12" cy="12" r="3" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 360 B |
15
admin/icons/file-pen-line.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="m18.226 5.226-2.52-2.52A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-.351" />
|
||||||
|
<path d="M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z" />
|
||||||
|
<path d="M8 18h1" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 488 B |
16
admin/icons/file-plus-corner.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
|
||||||
|
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
|
||||||
|
<path d="M9 15h6" />
|
||||||
|
<path d="M12 18v-6" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 421 B |
17
admin/icons/file-text.svg
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
|
||||||
|
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
|
||||||
|
<path d="M10 9H8" />
|
||||||
|
<path d="M16 13H8" />
|
||||||
|
<path d="M16 17H8" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 444 B |
1
admin/icons/globe.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-globe-icon lucide-globe"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>
|
||||||
|
After Width: | Height: | Size: 344 B |
1
admin/icons/image.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-image-icon lucide-file-image"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><circle cx="10" cy="12" r="2"/><path d="m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22"/></svg>
|
||||||
|
After Width: | Height: | Size: 490 B |
15
admin/icons/log-out.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="m16 17 5-5-5-5" />
|
||||||
|
<path d="M21 12H9" />
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 317 B |
1
admin/icons/notebook-pen.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-notebook-pen-icon lucide-notebook-pen"><path d="M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4"/><path d="M2 6h4"/><path d="M2 10h4"/><path d="M2 14h4"/><path d="M2 18h4"/><path d="M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z"/></svg>
|
||||||
|
After Width: | Height: | Size: 534 B |
1
admin/icons/paintbrush.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-paintbrush-icon lucide-paintbrush"><path d="m14.622 17.897-10.68-2.913"/><path d="M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z"/><path d="M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15"/></svg>
|
||||||
|
After Width: | Height: | Size: 646 B |
1
admin/icons/panel-right-close.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-panel-right-close-icon lucide-panel-right-close"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M15 3v18"/><path d="m8 9 3 3-3 3"/></svg>
|
||||||
|
After Width: | Height: | Size: 350 B |
15
admin/icons/save.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" />
|
||||||
|
<path d="M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" />
|
||||||
|
<path d="M7 3v4a1 1 0 0 0 1 1h7" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 417 B |
1
admin/icons/search.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-search-icon lucide-search"><path d="m21 21-4.34-4.34"/><circle cx="11" cy="11" r="8"/></svg>
|
||||||
|
After Width: | Height: | Size: 294 B |
14
admin/icons/settings.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" />
|
||||||
|
<circle cx="12" cy="12" r="3" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 586 B |
73
admin/icons/sprite.svg
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" style="display:none">
|
||||||
|
<symbol id="icon-search" viewBox="0 0 24 24"><path d="m21 21-4.34-4.34"/><circle cx="11" cy="11" r="8"/></symbol>
|
||||||
|
<symbol id="icon-notebook-pen" viewBox="0 0 24 24"><path d="M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4"/><path d="M2 6h4"/><path d="M2 10h4"/><path d="M2 14h4"/><path d="M2 18h4"/><path d="M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z"/></symbol>
|
||||||
|
<symbol id="icon-file-text" viewBox="0 0 24 24"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
|
||||||
|
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
|
||||||
|
<path d="M10 9H8" />
|
||||||
|
<path d="M16 13H8" />
|
||||||
|
<path d="M16 17H8" /></symbol>
|
||||||
|
<symbol id="icon-file-plus-corner" viewBox="0 0 24 24"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
|
||||||
|
<path d="M14 2v5a1 1 0 0 0 1 1h5" />
|
||||||
|
<path d="M9 15h6" />
|
||||||
|
<path d="M12 18v-6" /></symbol>
|
||||||
|
<symbol id="icon-settings" viewBox="0 0 24 24"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" />
|
||||||
|
<circle cx="12" cy="12" r="3" /></symbol>
|
||||||
|
<symbol id="icon-log-out" viewBox="0 0 24 24"><path d="m16 17 5-5-5-5" />
|
||||||
|
<path d="M21 12H9" />
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" /></symbol>
|
||||||
|
<symbol id="icon-file-pen-line" viewBox="0 0 24 24"><path d="m18.226 5.226-2.52-2.52A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-.351" />
|
||||||
|
<path d="M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z" />
|
||||||
|
<path d="M8 18h1" /></symbol>
|
||||||
|
<symbol id="icon-circle-x" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" />
|
||||||
|
<path d="m15 9-6 6" />
|
||||||
|
<path d="m9 9 6 6" /></symbol>
|
||||||
|
<symbol id="icon-save" viewBox="0 0 24 24"><path d="M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" />
|
||||||
|
<path d="M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" />
|
||||||
|
<path d="M7 3v4a1 1 0 0 0 1 1h7" /></symbol>
|
||||||
|
<symbol id="icon-eye" viewBox="0 0 24 24"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" />
|
||||||
|
<circle cx="12" cy="12" r="3" /></symbol>
|
||||||
|
<symbol id="icon-upload" viewBox="0 0 24 24"><path d="M12 3v12" />
|
||||||
|
<path d="m17 8-5-5-5 5" />
|
||||||
|
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /></symbol>
|
||||||
|
<symbol id="icon-arrow-left" viewBox="0 0 24 24"><path d="m12 19-7-7 7-7" />
|
||||||
|
<path d="M19 12H5" /></symbol>
|
||||||
|
<symbol id="icon-copy" viewBox="0 0 24 24"><rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
|
||||||
|
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /></symbol>
|
||||||
|
<symbol id="icon-circle-check" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" />
|
||||||
|
<path d="m9 12 2 2 4-4" /></symbol>
|
||||||
|
<symbol id="icon-circle-gauge" viewBox="0 0 24 24"><path d="M15.6 2.7a10 10 0 1 0 5.7 5.7" />
|
||||||
|
<circle cx="12" cy="12" r="2" />
|
||||||
|
<path d="M13.4 10.6 19 5" /></symbol>
|
||||||
|
<symbol id="icon-calendar" viewBox="0 0 24 24"><path d="M8 2v4" />
|
||||||
|
<path d="M16 2v4" />
|
||||||
|
<rect width="18" height="18" x="3" y="4" rx="2" />
|
||||||
|
<path d="M3 10h18" /></symbol>
|
||||||
|
<symbol id="icon-toggle-right" viewBox="0 0 24 24"><circle cx="15" cy="12" r="3" />
|
||||||
|
<rect width="20" height="14" x="2" y="5" rx="7" /></symbol>
|
||||||
|
<symbol id="icon-globe" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" />
|
||||||
|
<path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
|
||||||
|
<path d="M2 12h20" /></symbol>
|
||||||
|
<symbol id="icon-braces" viewBox="0 0 24 24"><path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1" />
|
||||||
|
<path d="M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1" /></symbol>
|
||||||
|
<symbol id="icon-user" viewBox="0 0 24 24"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
|
||||||
|
<circle cx="12" cy="7" r="4" /></symbol>
|
||||||
|
<symbol id="icon-paintbrush" viewBox="0 0 24 24"><path d="m14.622 17.897-10.68-2.913" />
|
||||||
|
<path d="M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z" />
|
||||||
|
<path d="M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15" /></symbol>
|
||||||
|
<symbol id="icon-menu" viewBox="0 0 24 24"><line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="18" y2="18"/></symbol>
|
||||||
|
<symbol id="icon-panel-left-close" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/><path d="m16 15-3-3 3-3"/></symbol>
|
||||||
|
<symbol id="icon-panel-left-open" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/><path d="m14 9 3 3-3 3"/></symbol>
|
||||||
|
<symbol id="icon-panel-right-close" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M15 3v18"/><path d="m8 9 3 3-3 3"/></symbol>
|
||||||
|
<symbol id="icon-upgrade" viewBox="0 0 24 24"><path d="M12 2a10 10 0 0 1 7.38 16.75" />
|
||||||
|
<path d="m16 12-4-4-4 4" />
|
||||||
|
<path d="M12 16V8" />
|
||||||
|
<path d="M2.5 8.875a10 10 0 0 0-.5 3" />
|
||||||
|
<path d="M2.83 16a10 10 0 0 0 2.43 3.4" />
|
||||||
|
<path d="M4.636 5.235a10 10 0 0 1 .891-.857" />
|
||||||
|
<path d="M8.644 21.42a10 10 0 0 0 7.631-.38" /></symbol>
|
||||||
|
<symbol id="icon-image" viewBox="0 0 24 24"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><circle cx="10" cy="12" r="2"/><path d="m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22"/></symbol>
|
||||||
|
<symbol id="icon-tag" viewBox="0 0 24 24"><path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r=".5" fill="currentColor"/></symbol>
|
||||||
|
<symbol id="icon-download" viewBox="0 0 24 24"><path d="M12 15V3" />
|
||||||
|
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||||
|
<path d="m7 10 5 5 5-5" /></symbol>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 6.3 KiB |
1
admin/icons/toggle-right.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right-icon lucide-toggle-right"><circle cx="15" cy="12" r="3"/><rect width="20" height="14" x="2" y="5" rx="7"/></svg>
|
||||||
|
After Width: | Height: | Size: 327 B |
1
admin/icons/upgrade.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-fading-arrow-up-icon lucide-circle-fading-arrow-up"><path d="M12 2a10 10 0 0 1 7.38 16.75"/><path d="m16 12-4-4-4 4"/><path d="M12 16V8"/><path d="M2.5 8.875a10 10 0 0 0-.5 3"/><path d="M2.83 16a10 10 0 0 0 2.43 3.4"/><path d="M4.636 5.235a10 10 0 0 1 .891-.857"/><path d="M8.644 21.42a10 10 0 0 0 7.631-.38"/></svg>
|
||||||
|
After Width: | Height: | Size: 525 B |
15
admin/icons/upload.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M12 3v12" />
|
||||||
|
<path d="m17 8-5-5-5 5" />
|
||||||
|
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 318 B |
1
admin/icons/user.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-user-icon lucide-user"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
|
||||||
|
After Width: | Height: | Size: 314 B |
358
admin/images.php
Normal file
|
|
@ -0,0 +1,358 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$deleted = isset($_GET['deleted']);
|
||||||
|
$deleteError = trim((string) ($_GET['delete_error'] ?? ''));
|
||||||
|
$search = trim((string) ($_GET['q'] ?? ''));
|
||||||
|
$perPage = 35;
|
||||||
|
$page = max(1, (int) ($_GET['page'] ?? 1));
|
||||||
|
|
||||||
|
// Collect all images from all slug folders
|
||||||
|
$allImages = [];
|
||||||
|
|
||||||
|
if (is_dir(PUREBLOG_CONTENT_IMAGES_PATH)) {
|
||||||
|
$slugFolders = glob(PUREBLOG_CONTENT_IMAGES_PATH . '/*', GLOB_ONLYDIR) ?: [];
|
||||||
|
foreach ($slugFolders as $folderPath) {
|
||||||
|
$slug = basename($folderPath);
|
||||||
|
if (!is_safe_image_slug($slug)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach (glob($folderPath . '/*') ?: [] as $file) {
|
||||||
|
if (!is_file($file)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$basename = basename($file);
|
||||||
|
$ext = strtolower(pathinfo($basename, PATHINFO_EXTENSION));
|
||||||
|
if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif'], true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$altText = pathinfo($basename, PATHINFO_FILENAME) ?: 'image';
|
||||||
|
$url = base_path() . '/content/images/' . $slug . '/' . $basename;
|
||||||
|
$allImages[] = [
|
||||||
|
'slug' => $slug,
|
||||||
|
'filename' => $basename,
|
||||||
|
'url' => $url,
|
||||||
|
'markdown' => '',
|
||||||
|
'mtime' => filemtime($file) ?: 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by search
|
||||||
|
if ($search !== '') {
|
||||||
|
$allImages = array_values(array_filter(
|
||||||
|
$allImages,
|
||||||
|
fn($img) => stripos($img['filename'], $search) !== false
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort newest first
|
||||||
|
usort($allImages, fn($a, $b) => $b['mtime'] <=> $a['mtime']);
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
$totalImages = count($allImages);
|
||||||
|
$totalPages = $totalImages > 0 ? (int) ceil($totalImages / $perPage) : 1;
|
||||||
|
$page = min($page, $totalPages);
|
||||||
|
$offset = ($page - 1) * $perPage;
|
||||||
|
$pageImages = array_slice($allImages, $offset, $perPage);
|
||||||
|
|
||||||
|
// Preload all posts and pages indexed by slug
|
||||||
|
$contentBySlug = [];
|
||||||
|
foreach (get_all_posts(true) as $p) {
|
||||||
|
if (!empty($p['slug'])) {
|
||||||
|
$contentBySlug[$p['slug']] = [
|
||||||
|
'title' => $p['title'] ?? $p['slug'],
|
||||||
|
'slug' => $p['slug'],
|
||||||
|
'type' => 'post',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (get_all_pages(true) as $p) {
|
||||||
|
if (!empty($p['slug'])) {
|
||||||
|
$contentBySlug[$p['slug']] = [
|
||||||
|
'title' => $p['title'] ?? $p['slug'],
|
||||||
|
'slug' => $p['slug'],
|
||||||
|
'type' => 'page',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build usage map by scanning all post/page .md files once
|
||||||
|
$usageMap = [];
|
||||||
|
foreach ([
|
||||||
|
['dir' => PUREBLOG_POSTS_PATH, 'type' => 'post'],
|
||||||
|
['dir' => PUREBLOG_PAGES_PATH, 'type' => 'page'],
|
||||||
|
] as $source) {
|
||||||
|
if (!is_dir($source['dir'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach (glob($source['dir'] . '/*.md') ?: [] as $mdFile) {
|
||||||
|
$raw = file_get_contents($mdFile);
|
||||||
|
if ($raw === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!preg_match_all('#/content/images/([^/\s\)\'"]+)/([^\s\)\'"]+)#', $raw, $matches, PREG_SET_ORDER)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$parsed = parse_post_file($mdFile);
|
||||||
|
$front = $parsed['front_matter'];
|
||||||
|
$entry = [
|
||||||
|
'title' => $front['title'] ?? basename($mdFile),
|
||||||
|
'slug' => $front['slug'] ?? '',
|
||||||
|
'type' => $source['type'],
|
||||||
|
];
|
||||||
|
$seenKeys = [];
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$key = $match[1] . '/' . $match[2];
|
||||||
|
if (isset($seenKeys[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$seenKeys[$key] = true;
|
||||||
|
$usageMap[$key][] = $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach usage info to the current page of images only
|
||||||
|
foreach ($pageImages as &$image) {
|
||||||
|
$imgKey = $image['slug'] . '/' . $image['filename'];
|
||||||
|
$usedIn = $usageMap[$imgKey] ?? [];
|
||||||
|
|
||||||
|
if (empty($usedIn) && isset($contentBySlug[$image['slug']])) {
|
||||||
|
$usedIn = [$contentBySlug[$image['slug']]];
|
||||||
|
}
|
||||||
|
|
||||||
|
$image['used_in'] = $usedIn;
|
||||||
|
$image['referenced_in'] = $usageMap[$imgKey] ?? [];
|
||||||
|
$image['thumb_url'] = get_image_thumb_url($image['slug'], $image['filename']);
|
||||||
|
}
|
||||||
|
unset($image);
|
||||||
|
|
||||||
|
$adminTitle = t('admin.images.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main>
|
||||||
|
<h1><?= e(t('admin.images.heading')) ?></h1>
|
||||||
|
|
||||||
|
<?php if ($deleted): ?>
|
||||||
|
<p class="notice" data-auto-dismiss><?= e(t('admin.images.deleted')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($deleteError !== ''): ?>
|
||||||
|
<p class="notice delete" data-auto-dismiss><?= e($deleteError) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="get" action="<?= base_path() ?>/admin/images.php" class="image-search-form">
|
||||||
|
<label class="hidden" for="q"><?= e(t('admin.images.search_label')) ?></label>
|
||||||
|
<input type="search" id="q" name="q" value="<?= e($search) ?>" placeholder="<?= e(t('admin.images.search_placeholder')) ?>">
|
||||||
|
<button type="submit">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-search"></use></svg>
|
||||||
|
<?= e(t('admin.images.search_label')) ?>
|
||||||
|
</button>
|
||||||
|
<?php if ($search !== ''): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/images.php" class="link-button delete">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.images.clear_search')) ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if (!$allImages): ?>
|
||||||
|
<p><?= e(t('admin.images.no_images')) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="image-library-grid">
|
||||||
|
<?php foreach ($pageImages as $i => $image): ?>
|
||||||
|
<?php $dialogId = 'delete-warn-' . $i; ?>
|
||||||
|
<div class="image-library-card">
|
||||||
|
<img src="<?= e($image['thumb_url']) ?>" class="image-library-thumb" alt="<?= e($image['filename']) ?>" loading="lazy" data-url="<?= e($image['url']) ?>" data-filename="<?= e($image['filename']) ?>">
|
||||||
|
<div class="image-library-info">
|
||||||
|
<code class="image-library-name" title="<?= e($image['filename']) ?>"><?= e($image['filename']) ?></code>
|
||||||
|
<div class="image-library-usage">
|
||||||
|
<span class="image-library-usage-label"><?= e(t('admin.images.used_in_label')) ?></span>
|
||||||
|
<?php if (empty($image['used_in'])): ?>
|
||||||
|
<span class="image-usage-fallback" title="<?= e($image['slug']) ?>"><?= e($image['slug']) ?></span>
|
||||||
|
<?php elseif (count($image['used_in']) === 1): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/edit-<?= e($image['used_in'][0]['type']) ?>.php?slug=<?= urlencode($image['used_in'][0]['slug']) ?>" class="image-usage-link" title="<?= e($image['used_in'][0]['title']) ?>"><?= e($image['used_in'][0]['title']) ?></a>
|
||||||
|
<?php else: ?>
|
||||||
|
<details class="image-usage-dropdown">
|
||||||
|
<summary class="image-usage-summary" title="<?= e(implode(', ', array_column($image['used_in'], 'title'))) ?>">
|
||||||
|
<?= e(t('admin.images.used_in_count', ['count' => count($image['used_in'])])) ?>
|
||||||
|
<svg class="icon icon-chevron" aria-hidden="true"><use href="#icon-arrow-left"></use></svg>
|
||||||
|
</summary>
|
||||||
|
<div class="image-usage-menu">
|
||||||
|
<div class="image-usage-menu-header"><?= e(t('admin.images.used_in_label')) ?></div>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($image['used_in'] as $usage): ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?= base_path() ?>/admin/edit-<?= e($usage['type']) ?>.php?slug=<?= urlencode($usage['slug']) ?>" title="<?= e($usage['title']) ?>">
|
||||||
|
<span class="image-usage-badge-type"><?= e(t('admin.images.type_' . $usage['type'])) ?></span>
|
||||||
|
<span class="image-usage-item-title"><?= e($usage['title']) ?></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="image-library-actions">
|
||||||
|
<button type="button" class="link-button copy-markdown" data-markdown="<?= e($image['markdown']) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-copy"></use></svg>
|
||||||
|
<?= e(t('admin.editor.copy')) ?>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<?php if (!empty($image['referenced_in'])): ?>
|
||||||
|
<button type="button" class="link-button delete" onclick="document.getElementById('<?= e($dialogId) ?>').showModal()">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.editor.delete')) ?>
|
||||||
|
</button>
|
||||||
|
<dialog id="<?= e($dialogId) ?>" class="image-delete-dialog">
|
||||||
|
<p><?= e(t('admin.images.delete_used_warning')) ?></p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($image['referenced_in'] as $usage): ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?= base_path() ?>/admin/edit-<?= e($usage['type']) ?>.php?slug=<?= urlencode($usage['slug']) ?>" target="_blank" rel="noopener noreferrer">
|
||||||
|
<?= e($usage['title']) ?>
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<div class="image-delete-dialog-actions">
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-image-library.php" class="inline-form">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($image['slug']) ?>">
|
||||||
|
<input type="hidden" name="filename" value="<?= e($image['filename']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" class="delete">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.images.delete_anyway')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<button type="button" onclick="this.closest('dialog').close()">
|
||||||
|
<?= e(t('admin.images.cancel')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
<?php else: ?>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/delete-image-library.php" class="inline-form" onsubmit="return confirm('<?= e(t('admin.images.delete_confirm')) ?>')">
|
||||||
|
<input type="hidden" name="slug" value="<?= e($image['slug']) ?>">
|
||||||
|
<input type="hidden" name="filename" value="<?= e($image['filename']) ?>">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" class="link-button delete">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.editor.delete')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php if ($totalPages > 1): ?>
|
||||||
|
<?php $pageParams = $search !== '' ? ['q' => $search] : []; ?>
|
||||||
|
<nav class="pagination">
|
||||||
|
<?php if ($page > 1): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/images.php?<?= e(http_build_query($pageParams + ['page' => $page - 1])) ?>"><?= e(t('admin.images.pagination_prev')) ?></a>
|
||||||
|
<?php else: ?>
|
||||||
|
<span></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($page < $totalPages): ?>
|
||||||
|
<a href="<?= base_path() ?>/admin/images.php?<?= e(http_build_query($pageParams + ['page' => $page + 1])) ?>"><?= e(t('admin.images.pagination_next')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</nav>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<dialog id="image-lightbox" class="image-lightbox">
|
||||||
|
<div class="image-lightbox-content">
|
||||||
|
<div class="image-lightbox-header">
|
||||||
|
<code id="lightbox-filename" class="image-lightbox-title"></code>
|
||||||
|
<button type="button" class="image-lightbox-close" onclick="document.getElementById('image-lightbox').close()" aria-label="<?= e(t('admin.images.cancel')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="image-lightbox-body">
|
||||||
|
<img id="lightbox-img" class="image-lightbox-img" src="" alt="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const basePath = <?= json_encode(base_path(), JSON_HEX_TAG) ?>;
|
||||||
|
const strings = {
|
||||||
|
copied: <?= json_encode(t('admin.editor.js_copied'), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) ?>,
|
||||||
|
copy: <?= json_encode(t('admin.editor.copy'), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) ?>,
|
||||||
|
copyFailed:<?= json_encode(t('admin.editor.js_copy_failed'),JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT) ?>,
|
||||||
|
};
|
||||||
|
|
||||||
|
const lightbox = document.getElementById('image-lightbox');
|
||||||
|
const lightboxImg = document.getElementById('lightbox-img');
|
||||||
|
const lightboxFilename = document.getElementById('lightbox-filename');
|
||||||
|
|
||||||
|
function openLightbox(url, filename) {
|
||||||
|
if (!lightbox || !lightboxImg) return;
|
||||||
|
lightboxImg.src = url;
|
||||||
|
lightboxImg.alt = filename;
|
||||||
|
if (lightboxFilename) {
|
||||||
|
lightboxFilename.textContent = filename;
|
||||||
|
}
|
||||||
|
lightbox.showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.image-library-thumb').forEach((thumb) => {
|
||||||
|
thumb.addEventListener('click', () => {
|
||||||
|
const url = thumb.getAttribute('data-url') || thumb.getAttribute('src');
|
||||||
|
const filename = thumb.getAttribute('data-filename') || thumb.getAttribute('alt') || '';
|
||||||
|
if (url) openLightbox(url, filename);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (lightbox) {
|
||||||
|
lightbox.addEventListener('click', (e) => {
|
||||||
|
if (e.target === lightbox) lightbox.close();
|
||||||
|
});
|
||||||
|
lightbox.addEventListener('close', () => {
|
||||||
|
lightboxImg.src = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.copy-markdown').forEach((button) => {
|
||||||
|
button.addEventListener('click', async () => {
|
||||||
|
const markdown = button.getAttribute('data-markdown') || '';
|
||||||
|
if (markdown === '') return;
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(markdown);
|
||||||
|
button.innerHTML = '<svg class="icon" aria-hidden="true"><use href="' + basePath + '/admin/icons/sprite.svg#icon-circle-check"></use></svg> ' + strings.copied;
|
||||||
|
setTimeout(() => {
|
||||||
|
button.innerHTML = '<svg class="icon" aria-hidden="true"><use href="' + basePath + '/admin/icons/sprite.svg#icon-copy"></use></svg> ' + strings.copy;
|
||||||
|
}, 1500);
|
||||||
|
} catch (e) {
|
||||||
|
alert(strings.copyFailed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.image-delete-dialog').forEach((dialog) => {
|
||||||
|
dialog.addEventListener('click', (e) => {
|
||||||
|
if (e.target === dialog) dialog.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('click', (e) => {
|
||||||
|
document.querySelectorAll('.image-usage-dropdown[open]').forEach((dropdown) => {
|
||||||
|
if (!dropdown.contains(e.target)) {
|
||||||
|
dropdown.removeAttribute('open');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
BIN
admin/images/layouts/layout-archive-dark.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
admin/images/layouts/layout-archive-light.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
admin/images/layouts/layout-excerpt-dark.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
admin/images/layouts/layout-excerpt-light.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
admin/images/layouts/layout-full-dark.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
admin/images/layouts/layout-full-light.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
174
admin/index.php
Normal file
|
|
@ -0,0 +1,174 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/../functions.php';
|
||||||
|
|
||||||
|
require_setup_redirect();
|
||||||
|
|
||||||
|
start_admin_session();
|
||||||
|
maybe_restore_admin_from_cookie();
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
$error = '';
|
||||||
|
$username = '';
|
||||||
|
$now = time();
|
||||||
|
$clientIp = (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||||
|
$failureState = get_login_failure_state($clientIp);
|
||||||
|
$lockoutUntil = $failureState['lockout_until'];
|
||||||
|
$isLockedOut = $lockoutUntil > $now;
|
||||||
|
|
||||||
|
if (is_admin_logged_in()) {
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
$adminLanding = (!$blogPostsEnabled || ($config['admin_homepage'] ?? 'dashboard') === 'content') ? 'content.php' : 'dashboard.php';
|
||||||
|
header('Location: ' . base_path() . '/admin/' . $adminLanding);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$isMfaPending = !empty($_SESSION['mfa_pending']);
|
||||||
|
|
||||||
|
// Handle cancel MFA action
|
||||||
|
if (isset($_GET['cancel_mfa']) && $isMfaPending) {
|
||||||
|
unset($_SESSION['mfa_pending'], $_SESSION['mfa_remember_me'], $_SESSION['mfa_username']);
|
||||||
|
header('Location: ' . base_path() . '/admin/index.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
verify_csrf();
|
||||||
|
if ($isLockedOut) {
|
||||||
|
$remaining = $lockoutUntil - $now;
|
||||||
|
$minutes = (int) ceil($remaining / 60);
|
||||||
|
$error = t('admin.login.error_lockout', ['minutes' => $minutes]);
|
||||||
|
} elseif ($isMfaPending) {
|
||||||
|
// Step 2: MFA Verification
|
||||||
|
$mfaCode = trim((string) ($_POST['mfa_code'] ?? ''));
|
||||||
|
$mfaSecret = (string) ($config['mfa_secret'] ?? '');
|
||||||
|
$mfaBackupCodes = (array) ($config['mfa_backup_codes'] ?? []);
|
||||||
|
|
||||||
|
$mfaVerified = false;
|
||||||
|
$usedBackupIndex = null;
|
||||||
|
|
||||||
|
if ($mfaCode !== '' && $mfaSecret !== '' && totp_verify_code($mfaSecret, $mfaCode)) {
|
||||||
|
$mfaVerified = true;
|
||||||
|
} elseif ($mfaCode !== '' && !empty($mfaBackupCodes)) {
|
||||||
|
$usedBackupIndex = totp_verify_backup_code($mfaCode, $mfaBackupCodes);
|
||||||
|
if ($usedBackupIndex !== null) {
|
||||||
|
$mfaVerified = true;
|
||||||
|
// Remove used backup code from config
|
||||||
|
array_splice($mfaBackupCodes, $usedBackupIndex, 1);
|
||||||
|
$config['mfa_backup_codes'] = $mfaBackupCodes;
|
||||||
|
save_config($config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($mfaVerified) {
|
||||||
|
session_regenerate_id(true);
|
||||||
|
$_SESSION['is_admin'] = true;
|
||||||
|
$rememberMe = !empty($_SESSION['mfa_remember_me']);
|
||||||
|
unset($_SESSION['mfa_pending'], $_SESSION['mfa_remember_me'], $_SESSION['mfa_username']);
|
||||||
|
clear_login_failures($clientIp);
|
||||||
|
if ($rememberMe) {
|
||||||
|
set_remember_me_cookie();
|
||||||
|
}
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
$adminLanding = (!$blogPostsEnabled || ($config['admin_homepage'] ?? 'dashboard') === 'content') ? 'content.php' : 'dashboard.php';
|
||||||
|
header('Location: ' . base_path() . '/admin/' . $adminLanding);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$state = record_login_failure($clientIp);
|
||||||
|
if ($state['lockout_until'] > $now) {
|
||||||
|
$lockoutUntil = $state['lockout_until'];
|
||||||
|
$isLockedOut = true;
|
||||||
|
$error = t('admin.login.error_lockout_5');
|
||||||
|
} else {
|
||||||
|
$error = t('admin.login.mfa_error_invalid');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Step 1: Username & Password Verification
|
||||||
|
$username = trim($_POST['username'] ?? '');
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
|
||||||
|
if ($username !== '' && hash_equals($config['admin_username'] ?? '', $username)
|
||||||
|
&& password_verify($password, $config['admin_password_hash'] ?? '')
|
||||||
|
) {
|
||||||
|
$mfaActive = !empty($config['mfa_enabled']) && !empty($config['mfa_secret']);
|
||||||
|
if ($mfaActive) {
|
||||||
|
session_regenerate_id(true);
|
||||||
|
$_SESSION['mfa_pending'] = true;
|
||||||
|
$_SESSION['mfa_remember_me'] = !empty($_POST['remember_me']);
|
||||||
|
$_SESSION['mfa_username'] = $username;
|
||||||
|
$isMfaPending = true;
|
||||||
|
} else {
|
||||||
|
session_regenerate_id(true);
|
||||||
|
$_SESSION['is_admin'] = true;
|
||||||
|
clear_login_failures($clientIp);
|
||||||
|
if (!empty($_POST['remember_me'])) {
|
||||||
|
set_remember_me_cookie();
|
||||||
|
}
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
$adminLanding = (!$blogPostsEnabled || ($config['admin_homepage'] ?? 'dashboard') === 'content') ? 'content.php' : 'dashboard.php';
|
||||||
|
header('Location: ' . base_path() . '/admin/' . $adminLanding);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$state = record_login_failure($clientIp);
|
||||||
|
if ($state['lockout_until'] > $now) {
|
||||||
|
$lockoutUntil = $state['lockout_until'];
|
||||||
|
$isLockedOut = true;
|
||||||
|
$error = t('admin.login.error_lockout_5');
|
||||||
|
} else {
|
||||||
|
$error = t('admin.login.error_invalid');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = $isMfaPending ? t('admin.login.mfa_page_title') : t('admin.login.page_title');
|
||||||
|
$hideAdminNav = true;
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="narrow">
|
||||||
|
<br>
|
||||||
|
<?php if ($isMfaPending): ?>
|
||||||
|
<h1><?= e(t('admin.login.mfa_heading')) ?></h1>
|
||||||
|
<p><?= e(t('admin.login.mfa_prompt')) ?></p>
|
||||||
|
<?php if ($error !== ''): ?>
|
||||||
|
<p class="notice delete"><?= e($error) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form method="post">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<label for="mfa_code"><?= e(t('admin.login.mfa_code_label')) ?></label>
|
||||||
|
<input type="text" id="mfa_code" name="mfa_code" autofocus inputmode="numeric" autocomplete="one-time-code" placeholder="123456" required<?= $isLockedOut ? ' disabled' : '' ?>>
|
||||||
|
<div style="display: flex; gap: 0.5rem; align-items: center; margin-top: 1.25rem;">
|
||||||
|
<button type="submit"<?= $isLockedOut ? ' disabled' : '' ?>><svg class="icon" aria-hidden="true"><use href="#icon-circle-check"></use></svg> <?= e(t('admin.login.mfa_submit')) ?></button>
|
||||||
|
<a href="?cancel_mfa=1" class="button link-button"><svg class="icon" aria-hidden="true"><use href="#icon-arrow-left"></use></svg> <?= e(t('admin.login.mfa_cancel')) ?></a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<h1><?= e(t('admin.login.heading')) ?></h1>
|
||||||
|
<?php if (!empty($_GET['setup'])): ?>
|
||||||
|
<p><?= e(t('admin.login.setup_complete')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error !== ''): ?>
|
||||||
|
<p class="notice delete"><?= e($error) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form method="post">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<label for="username"><?= e(t('admin.login.username')) ?></label>
|
||||||
|
<input type="text" id="username" name="username" autofocus value="<?= e($username) ?>" required<?= $isLockedOut ? ' disabled' : '' ?>>
|
||||||
|
|
||||||
|
<label for="password"><?= e(t('admin.login.password')) ?></label>
|
||||||
|
<input type="password" id="password" name="password" required<?= $isLockedOut ? ' disabled' : '' ?>>
|
||||||
|
|
||||||
|
<label class="checkbox-label">
|
||||||
|
<input type="checkbox" name="remember_me" value="1"<?= $isLockedOut ? ' disabled' : '' ?>>
|
||||||
|
<?= e(t('admin.login.remember_me')) ?>
|
||||||
|
</label>
|
||||||
|
<button type="submit"<?= $isLockedOut ? ' disabled' : '' ?>><svg class="icon" aria-hidden="true"><use href="#icon-circle-check"></use></svg> <?= e(t('admin.login.submit')) ?></button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
848
admin/js/editor.js
Normal file
|
|
@ -0,0 +1,848 @@
|
||||||
|
(() => {
|
||||||
|
const config = window.PureblogEditorConfig || {};
|
||||||
|
const contentField = document.getElementById('content');
|
||||||
|
if (!contentField || typeof window.createSyntaxEditor !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const editorForm = document.getElementById(config.formId || '');
|
||||||
|
const slugField = document.getElementById('slug');
|
||||||
|
const statusField = document.getElementById('status');
|
||||||
|
const titleField = document.getElementById('title');
|
||||||
|
const descriptionField = document.getElementById('description');
|
||||||
|
const dateField = document.getElementById('date');
|
||||||
|
const tagsField = document.getElementById('tags');
|
||||||
|
const previewButton = document.getElementById('preview-button');
|
||||||
|
|
||||||
|
const uploadForm = document.querySelector('.upload-form');
|
||||||
|
const uploadInput = uploadForm?.querySelector('input[type="file"]');
|
||||||
|
const uploadButton = uploadForm?.querySelector('button[type="submit"]');
|
||||||
|
let allowUploadSubmit = false;
|
||||||
|
|
||||||
|
// Initialize syntax editor on the main content textarea
|
||||||
|
const mainEditor = window.createSyntaxEditor(contentField, 'markdown');
|
||||||
|
|
||||||
|
contentField.addEventListener('input', () => {
|
||||||
|
scheduleAutosave();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle Markdown shortcut keydown events for a textarea
|
||||||
|
function attachMarkdownShortcuts(textarea) {
|
||||||
|
textarea.addEventListener('keydown', (event) => {
|
||||||
|
const isCmdOrCtrl = event.metaKey || event.ctrlKey;
|
||||||
|
if (!isCmdOrCtrl || event.shiftKey || event.altKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const key = event.key.toLowerCase();
|
||||||
|
if (key === 'b') {
|
||||||
|
event.preventDefault();
|
||||||
|
wrapSelection(textarea, '**');
|
||||||
|
} else if (key === 'i') {
|
||||||
|
event.preventDefault();
|
||||||
|
wrapSelection(textarea, '*');
|
||||||
|
} else if (key === 'k') {
|
||||||
|
event.preventDefault();
|
||||||
|
insertLink(textarea);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
attachMarkdownShortcuts(contentField);
|
||||||
|
|
||||||
|
// Initialize syntax editor for layout markdown editors if any
|
||||||
|
const layoutEditors = [];
|
||||||
|
document.querySelectorAll('textarea[data-layout-markdown]').forEach((textarea) => {
|
||||||
|
const layoutEditor = window.createSyntaxEditor(textarea, 'markdown');
|
||||||
|
textarea.addEventListener('input', () => {
|
||||||
|
scheduleAutosave();
|
||||||
|
});
|
||||||
|
attachMarkdownShortcuts(textarea);
|
||||||
|
layoutEditors.push(layoutEditor);
|
||||||
|
});
|
||||||
|
|
||||||
|
function replaceTextareaRange(textarea, text, newSelectionStart, newSelectionEnd) {
|
||||||
|
textarea.focus();
|
||||||
|
if (!document.execCommand || !document.execCommand('insertText', false, text)) {
|
||||||
|
textarea.setRangeText(text, textarea.selectionStart, textarea.selectionEnd, 'end');
|
||||||
|
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
textarea.setSelectionRange(newSelectionStart, newSelectionEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapSelection(textarea, wrapper) {
|
||||||
|
const start = textarea.selectionStart;
|
||||||
|
const end = textarea.selectionEnd;
|
||||||
|
const selectedText = textarea.value.slice(start, end);
|
||||||
|
const newText = wrapper + selectedText + wrapper;
|
||||||
|
const wLen = wrapper.length;
|
||||||
|
|
||||||
|
if (selectedText.length > 0) {
|
||||||
|
replaceTextareaRange(textarea, newText, start + wLen, end + wLen);
|
||||||
|
} else {
|
||||||
|
replaceTextareaRange(textarea, newText, start + wLen, start + wLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertLink(textarea) {
|
||||||
|
const start = textarea.selectionStart;
|
||||||
|
const end = textarea.selectionEnd;
|
||||||
|
const selectedText = textarea.value.slice(start, end);
|
||||||
|
const newText = selectedText ? `[${selectedText}]()` : '[]()';
|
||||||
|
|
||||||
|
if (selectedText.length > 0) {
|
||||||
|
const cursorPos = start + selectedText.length + 3; // inside ()
|
||||||
|
replaceTextareaRange(textarea, newText, cursorPos, cursorPos);
|
||||||
|
} else {
|
||||||
|
const cursorPos = start + 1; // inside []
|
||||||
|
replaceTextareaRange(textarea, newText, cursorPos, cursorPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertTextAtCursor(textarea, text) {
|
||||||
|
const start = textarea.selectionStart;
|
||||||
|
const newCursor = start + text.length;
|
||||||
|
replaceTextareaRange(textarea, text, newCursor, newCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
const autosaveStatus = document.getElementById('autosave-status');
|
||||||
|
let autosaveTimer = null;
|
||||||
|
|
||||||
|
function setAutosaveStatus(text) {
|
||||||
|
if (autosaveStatus) autosaveStatus.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function discardAutosave() {
|
||||||
|
const slugValue = (slugField?.value ?? '').trim();
|
||||||
|
if (slugValue === '') return;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.set('csrf_token', config.csrfToken);
|
||||||
|
formData.set('action', 'discard');
|
||||||
|
formData.set('slug', slugValue);
|
||||||
|
formData.set('editor_type', config.editorType || 'post');
|
||||||
|
await fetch((config.basePath || '') + '/admin/autosave.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
credentials: 'same-origin',
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doAutosave() {
|
||||||
|
const slugValue = (slugField?.value ?? '').trim();
|
||||||
|
if (slugValue === '') return;
|
||||||
|
|
||||||
|
setAutosaveStatus(config.strings.autosaving);
|
||||||
|
try {
|
||||||
|
const formData = new FormData(editorForm);
|
||||||
|
formData.set('editor_type', config.editorType || 'post');
|
||||||
|
formData.set('action', 'save');
|
||||||
|
const response = await fetch((config.basePath || '') + '/admin/autosave.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
credentials: 'same-origin',
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.success) {
|
||||||
|
const now = new Date();
|
||||||
|
setAutosaveStatus(config.strings.autosaved + ' ' + now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }));
|
||||||
|
} else {
|
||||||
|
setAutosaveStatus(config.strings.autosave_failed);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setAutosaveStatus(config.strings.autosave_failed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleAutosave() {
|
||||||
|
if ((slugField?.value ?? '').trim() === '') return;
|
||||||
|
clearTimeout(autosaveTimer);
|
||||||
|
autosaveTimer = setTimeout(doAutosave, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[titleField, slugField, descriptionField, dateField, tagsField].forEach((field) => {
|
||||||
|
field?.addEventListener('input', scheduleAutosave);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cancel any pending autosave timer on manual save (server deletes autosave file on save).
|
||||||
|
editorForm?.addEventListener('submit', () => { clearTimeout(autosaveTimer); });
|
||||||
|
|
||||||
|
// Show restore banner if an autosave exists.
|
||||||
|
if (config.autosave) {
|
||||||
|
const saved = config.autosave;
|
||||||
|
const time = new Date(saved.timestamp * 1000).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
|
|
||||||
|
const preview = document.createElement('div');
|
||||||
|
preview.className = 'autosave-preview';
|
||||||
|
preview.hidden = true;
|
||||||
|
preview.innerHTML =
|
||||||
|
(saved.title ? '<p><strong>' + config.strings.title_label + '</strong> ' + saved.title.replace(/</g, '<') + '</p>' : '') +
|
||||||
|
(saved.content ? '<pre class="autosave-preview-content">' + saved.content.replace(/</g, '<') + '</pre>' : '');
|
||||||
|
|
||||||
|
const banner = document.createElement('div');
|
||||||
|
banner.className = 'notice autosave-restore-notice';
|
||||||
|
banner.innerHTML =
|
||||||
|
config.strings.autosave_banner.replace('{time}', time) + ' ' +
|
||||||
|
'<button type="button" class="autosave-btn" id="autosave-view-btn">' + config.strings.view + '</button> ' +
|
||||||
|
'<button type="button" class="autosave-btn" id="autosave-restore-btn">' + config.strings.restore + '</button> ' +
|
||||||
|
'<button type="button" class="autosave-btn delete" id="autosave-discard-btn">' + config.strings.discard + '</button>';
|
||||||
|
|
||||||
|
const main = document.querySelector('main');
|
||||||
|
if (main) {
|
||||||
|
main.insertBefore(preview, main.firstChild);
|
||||||
|
main.insertBefore(banner, preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('autosave-view-btn')?.addEventListener('click', () => {
|
||||||
|
const isHidden = preview.hidden;
|
||||||
|
preview.hidden = !isHidden;
|
||||||
|
document.getElementById('autosave-view-btn').textContent = isHidden ? config.strings.hide : config.strings.view;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('autosave-restore-btn')?.addEventListener('click', () => {
|
||||||
|
const titleField2 = editorForm?.querySelector('[name="title"]');
|
||||||
|
const descField2 = editorForm?.querySelector('[name="description"]');
|
||||||
|
const tagsField2 = editorForm?.querySelector('[name="tags"]');
|
||||||
|
const dateField2 = editorForm?.querySelector('[name="date"]');
|
||||||
|
const navField2 = editorForm?.querySelector('[name="include_in_nav"]');
|
||||||
|
const statusField2 = editorForm?.querySelector('[name="status"]');
|
||||||
|
|
||||||
|
if (titleField2 && saved.title != null) titleField2.value = saved.title;
|
||||||
|
if (descField2 && saved.description != null) descField2.value = saved.description;
|
||||||
|
if (tagsField2 && saved.tags != null) {
|
||||||
|
tagsField2.value = saved.tags;
|
||||||
|
tagsField2.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
if (dateField2 && saved.date != null) dateField2.value = saved.date;
|
||||||
|
if (navField2 && saved.include_in_nav != null) navField2.value = saved.include_in_nav;
|
||||||
|
if (statusField2 && saved.status != null) statusField2.value = saved.status;
|
||||||
|
if (saved.content != null) {
|
||||||
|
mainEditor.updateCode(saved.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
banner.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('autosave-discard-btn')?.addEventListener('click', async () => {
|
||||||
|
await discardAutosave();
|
||||||
|
banner.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle editor scroll and cursor position restoration on form submit / reload
|
||||||
|
const scrollContainer = document.querySelector('.admin-main');
|
||||||
|
const pendingRestoreStr = sessionStorage.getItem('editor_pending_restore');
|
||||||
|
if (pendingRestoreStr) {
|
||||||
|
try {
|
||||||
|
const restoreData = JSON.parse(pendingRestoreStr);
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const urlSlug = (urlParams.get('slug') || '').trim();
|
||||||
|
const currentSlug = (slugField?.value ?? urlSlug ?? '').trim();
|
||||||
|
|
||||||
|
const savedSlug = (restoreData.slug || '').trim();
|
||||||
|
const isSlugMatch = savedSlug === currentSlug;
|
||||||
|
const isNewPostMatch = savedSlug === '' && currentSlug !== '';
|
||||||
|
const isUrlSlugMatch = savedSlug === urlSlug;
|
||||||
|
|
||||||
|
if (restoreData &&
|
||||||
|
restoreData.editorType === config.editorType &&
|
||||||
|
(isSlugMatch || isNewPostMatch || isUrlSlugMatch) &&
|
||||||
|
Date.now() - restoreData.timestamp < 10000) {
|
||||||
|
|
||||||
|
if ('scrollRestoration' in history) {
|
||||||
|
history.scrollRestoration = 'manual';
|
||||||
|
}
|
||||||
|
|
||||||
|
const restoreCursor = () => {
|
||||||
|
if (restoreData.cursor && typeof restoreData.cursor.start === 'number') {
|
||||||
|
try {
|
||||||
|
contentField.focus({ preventScroll: true });
|
||||||
|
contentField.setSelectionRange(restoreData.cursor.start, restoreData.cursor.end ?? restoreData.cursor.start);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreScroll = () => {
|
||||||
|
const scrollValue = parseInt(restoreData.scroll, 10);
|
||||||
|
if (!Number.isNaN(scrollValue)) {
|
||||||
|
if (scrollContainer) {
|
||||||
|
scrollContainer.scrollTop = scrollValue;
|
||||||
|
} else {
|
||||||
|
window.scrollTo(0, scrollValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
restoreCursor();
|
||||||
|
setTimeout(restoreCursor, 50);
|
||||||
|
|
||||||
|
restoreScroll();
|
||||||
|
setTimeout(restoreScroll, 50);
|
||||||
|
setTimeout(restoreScroll, 150);
|
||||||
|
setTimeout(restoreScroll, 300);
|
||||||
|
setTimeout(restoreScroll, 600);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
sessionStorage.removeItem('editor_pending_restore');
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveEditorStateToSession() {
|
||||||
|
try {
|
||||||
|
const state = {
|
||||||
|
scroll: scrollContainer ? scrollContainer.scrollTop : window.scrollY,
|
||||||
|
cursor: {
|
||||||
|
start: contentField.selectionStart,
|
||||||
|
end: contentField.selectionEnd,
|
||||||
|
},
|
||||||
|
editorType: config.editorType,
|
||||||
|
slug: (slugField?.value ?? '').trim(),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
sessionStorage.setItem('editor_pending_restore', JSON.stringify(state));
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
editorForm?.addEventListener('submit', () => {
|
||||||
|
saveEditorStateToSession();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (uploadInput && uploadButton) {
|
||||||
|
const toggleUpload = () => {
|
||||||
|
uploadButton.disabled = !uploadInput.files || uploadInput.files.length === 0;
|
||||||
|
};
|
||||||
|
uploadInput.addEventListener('change', toggleUpload);
|
||||||
|
toggleUpload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveEditorBeforeSidebarAction() {
|
||||||
|
clearTimeout(autosaveTimer);
|
||||||
|
|
||||||
|
const formData = new FormData(editorForm);
|
||||||
|
formData.set('ajax_save', '1');
|
||||||
|
const response = await fetch(editorForm.action || window.location.href, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
credentials: 'same-origin',
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(config.strings.save_failed);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
if (!data || !data.saved) {
|
||||||
|
throw new Error(config.strings.save_failed);
|
||||||
|
}
|
||||||
|
return data.slug || (slugField?.value ?? '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uploadForm && editorForm) {
|
||||||
|
uploadForm.addEventListener('submit', async (event) => {
|
||||||
|
if (allowUploadSubmit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
const savedSlug = await saveEditorBeforeSidebarAction();
|
||||||
|
const uploadSlug = uploadForm.querySelector('input[name="slug"]');
|
||||||
|
if (savedSlug && uploadSlug) {
|
||||||
|
uploadSlug.value = savedSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.editorType === 'post') {
|
||||||
|
const savedDate = (dateField?.value ?? '').trim();
|
||||||
|
const uploadDate = uploadForm.querySelector('input[name="date"]');
|
||||||
|
if (savedDate && uploadDate) {
|
||||||
|
uploadDate.value = savedDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveEditorStateToSession();
|
||||||
|
allowUploadSubmit = true;
|
||||||
|
uploadForm.submit();
|
||||||
|
} catch (error) {
|
||||||
|
alert(config.strings.save_before_upload);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save editor content before deleting an attached image in the sidebar
|
||||||
|
document.querySelectorAll('.image-list form.inline-form').forEach((deleteForm) => {
|
||||||
|
let allowDeleteSubmit = false;
|
||||||
|
deleteForm.addEventListener('submit', async (event) => {
|
||||||
|
if (allowDeleteSubmit || !editorForm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
await saveEditorBeforeSidebarAction();
|
||||||
|
saveEditorStateToSession();
|
||||||
|
allowDeleteSubmit = true;
|
||||||
|
deleteForm.submit();
|
||||||
|
} catch (error) {
|
||||||
|
alert(config.strings.save_failed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
previewButton?.addEventListener('click', () => {
|
||||||
|
const statusValue = statusField?.value ?? '';
|
||||||
|
const slugValue = (slugField?.value ?? '').trim();
|
||||||
|
if (statusValue === 'published' && slugValue !== '') {
|
||||||
|
window.open(`${config.basePath || ''}/${encodeURIComponent(slugValue)}`, '_blank');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const form = document.createElement('form');
|
||||||
|
form.method = 'post';
|
||||||
|
form.action = (config.basePath || '') + '/admin/preview.php';
|
||||||
|
form.target = '_blank';
|
||||||
|
|
||||||
|
const fields = [
|
||||||
|
{ name: 'editor_type', value: config.editorType || 'post' },
|
||||||
|
{ name: 'slug', value: slugField?.value ?? '' },
|
||||||
|
{ name: 'markdown', value: contentField.value },
|
||||||
|
{ name: 'title', value: titleField?.value ?? '' },
|
||||||
|
{ name: 'description', value: descriptionField?.value ?? '' },
|
||||||
|
{ name: 'csrf_token', value: config.csrfToken || '' },
|
||||||
|
];
|
||||||
|
|
||||||
|
if (config.editorType === 'post') {
|
||||||
|
fields.splice(3, 0, { name: 'date', value: dateField?.value ?? '' });
|
||||||
|
fields.splice(4, 0, { name: 'tags', value: tagsField?.value ?? '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutInput = editorForm?.querySelector('input[name="post_layout"]');
|
||||||
|
if (layoutInput) {
|
||||||
|
fields.push({ name: 'layout', value: layoutInput.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
editorForm?.querySelectorAll('[name^="layout_field__"]').forEach((el) => {
|
||||||
|
if (el.type === 'checkbox') {
|
||||||
|
fields.push({ name: el.name, value: el.checked ? '1' : '' });
|
||||||
|
} else if (el.type !== 'hidden') {
|
||||||
|
fields.push({ name: el.name, value: el.value });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fields.forEach(({ name, value }) => {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'hidden';
|
||||||
|
input.name = name;
|
||||||
|
input.value = value;
|
||||||
|
form.appendChild(input);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
form.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('keydown', (event) => {
|
||||||
|
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 's') {
|
||||||
|
event.preventDefault();
|
||||||
|
editorForm?.requestSubmit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const notices = document.querySelectorAll('[data-auto-dismiss]');
|
||||||
|
if (notices.length) {
|
||||||
|
setTimeout(() => {
|
||||||
|
notices.forEach((notice) => {
|
||||||
|
notice.style.opacity = '0';
|
||||||
|
notice.style.transform = 'translateX(30px)';
|
||||||
|
setTimeout(() => notice.remove(), 250);
|
||||||
|
});
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
['saved', 'uploaded', 'upload_error'].forEach((param) => url.searchParams.delete(param));
|
||||||
|
window.history.replaceState({}, document.title, url.toString());
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.copy-markdown').forEach((button) => {
|
||||||
|
button.addEventListener('click', async () => {
|
||||||
|
const markdown = button.getAttribute('data-markdown') || '';
|
||||||
|
if (markdown === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(markdown);
|
||||||
|
button.innerHTML = '<svg class="icon" aria-hidden="true"><use href="/admin/icons/sprite.svg#icon-circle-check"></use></svg> ' + config.strings.copied;
|
||||||
|
setTimeout(() => {
|
||||||
|
button.innerHTML = '<svg class="icon" aria-hidden="true"><use href="/admin/icons/sprite.svg#icon-copy"></use></svg> ' + config.strings.copy;
|
||||||
|
}, 1500);
|
||||||
|
} catch (error) {
|
||||||
|
alert(config.strings.copy_failed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Gallery Picker Dialogue & Cursor Tracking
|
||||||
|
let lastSavedCursor = null;
|
||||||
|
|
||||||
|
function recordEditorCursor() {
|
||||||
|
lastSavedCursor = {
|
||||||
|
start: contentField.selectionStart,
|
||||||
|
end: contentField.selectionEnd,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
['keyup', 'mouseup', 'touchend', 'input', 'focus', 'select'].forEach((evt) => {
|
||||||
|
contentField.addEventListener(evt, recordEditorCursor);
|
||||||
|
});
|
||||||
|
|
||||||
|
function createGalleryPickerDialog() {
|
||||||
|
let dialog = document.getElementById('gallery-picker-dialog');
|
||||||
|
if (!dialog) {
|
||||||
|
dialog = document.createElement('dialog');
|
||||||
|
dialog.id = 'gallery-picker-dialog';
|
||||||
|
dialog.className = 'gallery-picker-dialog';
|
||||||
|
document.body.appendChild(dialog);
|
||||||
|
|
||||||
|
dialog.addEventListener('click', (e) => {
|
||||||
|
if (e.target === dialog) {
|
||||||
|
dialog.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openGalleryPicker(triggerButton) {
|
||||||
|
const listItems = document.querySelectorAll('.image-list li');
|
||||||
|
if (!listItems.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialog = createGalleryPickerDialog();
|
||||||
|
const strings = config.strings || {};
|
||||||
|
const titleText = strings.gallery_picker_title || 'Select images for gallery';
|
||||||
|
const selectAllText = strings.gallery_picker_select_all || 'Select all';
|
||||||
|
const deselectAllText = strings.gallery_picker_deselect_all || 'Deselect all';
|
||||||
|
const cancelText = strings.gallery_picker_cancel || 'Cancel';
|
||||||
|
const noSelectedText = strings.gallery_picker_no_selected || 'Please select at least one image.';
|
||||||
|
|
||||||
|
const images = [];
|
||||||
|
listItems.forEach((li, idx) => {
|
||||||
|
const copyBtn = li.querySelector('.copy-markdown');
|
||||||
|
const imgEl = li.querySelector('.image-list-preview');
|
||||||
|
const codeEl = li.querySelector('code');
|
||||||
|
const markdown = copyBtn?.getAttribute('data-markdown') || '';
|
||||||
|
const src = imgEl?.getAttribute('src') || '';
|
||||||
|
const filename = codeEl?.textContent || `image-${idx + 1}`;
|
||||||
|
if (markdown) {
|
||||||
|
images.push({ id: `gp-img-${idx}`, markdown, src, filename });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!images.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.innerHTML = `
|
||||||
|
<h3>${titleText}</h3>
|
||||||
|
<div class="gallery-picker-toolbar">
|
||||||
|
<span class="gallery-picker-count" id="gallery-picker-count"></span>
|
||||||
|
<div class="gallery-picker-toolbar-actions">
|
||||||
|
<button type="button" class="link-button" id="gallery-picker-select-all">${selectAllText}</button>
|
||||||
|
<button type="button" class="link-button" id="gallery-picker-deselect-all">${deselectAllText}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ul class="gallery-picker-list">
|
||||||
|
${images.map(img => `
|
||||||
|
<li class="gallery-picker-item" data-id="${img.id}">
|
||||||
|
<input type="checkbox" id="${img.id}" value="${img.markdown.replace(/"/g, '"')}">
|
||||||
|
<img src="${img.src.replace(/"/g, '"')}" class="gallery-picker-thumb" alt="${img.filename.replace(/"/g, '"')}" loading="lazy">
|
||||||
|
<code class="gallery-picker-filename">${img.filename.replace(/</g, '<')}</code>
|
||||||
|
</li>
|
||||||
|
`).join('')}
|
||||||
|
</ul>
|
||||||
|
<div class="gallery-picker-footer">
|
||||||
|
<button type="button" class="link-button" id="gallery-picker-cancel">${cancelText}</button>
|
||||||
|
<button type="button" class="accent-button" id="gallery-picker-submit"></button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const countEl = dialog.querySelector('#gallery-picker-count');
|
||||||
|
const submitBtn = dialog.querySelector('#gallery-picker-submit');
|
||||||
|
const cancelBtn = dialog.querySelector('#gallery-picker-cancel');
|
||||||
|
const selectAllBtn = dialog.querySelector('#gallery-picker-select-all');
|
||||||
|
const deselectAllBtn = dialog.querySelector('#gallery-picker-deselect-all');
|
||||||
|
const checkboxes = dialog.querySelectorAll('.gallery-picker-item input[type="checkbox"]');
|
||||||
|
|
||||||
|
function updateCount() {
|
||||||
|
const selected = Array.from(checkboxes).filter(cb => cb.checked).length;
|
||||||
|
const countTemplate = strings.gallery_picker_count || '{selected} of {total} selected';
|
||||||
|
countEl.textContent = countTemplate.replace('{selected}', selected).replace('{total}', images.length);
|
||||||
|
|
||||||
|
const insertTemplate = strings.gallery_picker_insert || 'Insert gallery ({count})';
|
||||||
|
submitBtn.textContent = insertTemplate.replace('{count}', selected);
|
||||||
|
submitBtn.disabled = selected === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.querySelectorAll('.gallery-picker-item').forEach(item => {
|
||||||
|
item.addEventListener('click', (e) => {
|
||||||
|
if (e.target.tagName.toLowerCase() !== 'input') {
|
||||||
|
const cb = item.querySelector('input[type="checkbox"]');
|
||||||
|
if (cb) {
|
||||||
|
cb.checked = !cb.checked;
|
||||||
|
updateCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
checkboxes.forEach(cb => {
|
||||||
|
cb.addEventListener('change', updateCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
selectAllBtn.addEventListener('click', () => {
|
||||||
|
checkboxes.forEach(cb => { cb.checked = true; });
|
||||||
|
updateCount();
|
||||||
|
});
|
||||||
|
|
||||||
|
deselectAllBtn.addEventListener('click', () => {
|
||||||
|
checkboxes.forEach(cb => { cb.checked = false; });
|
||||||
|
updateCount();
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelBtn.addEventListener('click', () => {
|
||||||
|
dialog.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
submitBtn.addEventListener('click', async () => {
|
||||||
|
const selectedMarkdown = Array.from(checkboxes)
|
||||||
|
.filter(cb => cb.checked)
|
||||||
|
.map(cb => cb.value);
|
||||||
|
|
||||||
|
if (!selectedMarkdown.length) {
|
||||||
|
alert(noSelectedText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentCode = contentField.value;
|
||||||
|
let start = currentCode.length;
|
||||||
|
let end = currentCode.length;
|
||||||
|
|
||||||
|
if (lastSavedCursor && typeof lastSavedCursor.start === 'number') {
|
||||||
|
start = Math.max(0, Math.min(lastSavedCursor.start, currentCode.length));
|
||||||
|
end = Math.max(0, Math.min(lastSavedCursor.end, currentCode.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
let prefix = '\n\n';
|
||||||
|
let suffix = '\n\n';
|
||||||
|
if (start === 0 || currentCode.slice(0, start).endsWith('\n\n')) {
|
||||||
|
prefix = '';
|
||||||
|
} else if (currentCode.slice(0, start).endsWith('\n')) {
|
||||||
|
prefix = '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentCode.slice(end).startsWith('\n\n') || currentCode.slice(end) === '') {
|
||||||
|
suffix = '\n';
|
||||||
|
} else if (currentCode.slice(end).startsWith('\n')) {
|
||||||
|
suffix = '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
const gallerySnippet = `${prefix}::: gallery\n${selectedMarkdown.join('\n')}\n:::${suffix}`;
|
||||||
|
const newCursorPos = start + gallerySnippet.length;
|
||||||
|
|
||||||
|
contentField.setSelectionRange(start, end);
|
||||||
|
replaceTextareaRange(contentField, gallerySnippet, newCursorPos, newCursorPos);
|
||||||
|
lastSavedCursor = { start: newCursorPos, end: newCursorPos };
|
||||||
|
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(gallerySnippet.trim());
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
dialog.close();
|
||||||
|
|
||||||
|
if (triggerButton) {
|
||||||
|
const originalHtml = triggerButton.innerHTML;
|
||||||
|
const insertedText = strings.gallery_inserted || 'Gallery inserted';
|
||||||
|
triggerButton.innerHTML = '<svg class="icon" aria-hidden="true"><use href="/admin/icons/sprite.svg#icon-circle-check"></use></svg> ' + insertedText;
|
||||||
|
setTimeout(() => {
|
||||||
|
triggerButton.innerHTML = originalHtml;
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateCount();
|
||||||
|
dialog.showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.insert-gallery-btn').forEach((button) => {
|
||||||
|
button.addEventListener('mousedown', () => {
|
||||||
|
recordEditorCursor();
|
||||||
|
});
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
recordEditorCursor();
|
||||||
|
openGalleryPicker(button);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const featureImageInput = document.getElementById('feature-image-value');
|
||||||
|
|
||||||
|
document.querySelectorAll('.feature-image-check').forEach((checkbox) => {
|
||||||
|
checkbox.addEventListener('change', async () => {
|
||||||
|
const url = checkbox.getAttribute('data-url') || '';
|
||||||
|
const filename = checkbox.getAttribute('data-filename') || '';
|
||||||
|
const slugValue = (slugField?.value ?? '').trim();
|
||||||
|
|
||||||
|
if (slugValue === '') {
|
||||||
|
checkbox.checked = !checkbox.checked;
|
||||||
|
alert(config.editorType === 'post'
|
||||||
|
? config.strings.save_post_first
|
||||||
|
: config.strings.save_page_first);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkbox.checked) {
|
||||||
|
const currentUrl = featureImageInput?.value ?? '';
|
||||||
|
if (currentUrl !== '' && currentUrl !== url) {
|
||||||
|
const currentFilename = currentUrl.split('/').pop();
|
||||||
|
const confirmed = confirm(
|
||||||
|
(config.strings.feature_image_confirm || '')
|
||||||
|
.replace('{filename}', filename)
|
||||||
|
.replace('{current}', currentFilename)
|
||||||
|
);
|
||||||
|
if (!confirmed) {
|
||||||
|
checkbox.checked = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newFilename = checkbox.checked ? filename : '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('slug', slugValue);
|
||||||
|
formData.append('editor_type', config.editorType);
|
||||||
|
formData.append('filename', newFilename);
|
||||||
|
formData.append('csrf_token', config.csrfToken || '');
|
||||||
|
|
||||||
|
const response = await fetch((config.basePath || '') + '/admin/set-feature-image.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (!data.success) {
|
||||||
|
checkbox.checked = !checkbox.checked;
|
||||||
|
alert(config.strings.feature_image_failed || 'Failed to update feature image.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkbox.checked) {
|
||||||
|
document.querySelectorAll('.feature-image-check').forEach((cb) => {
|
||||||
|
if (cb !== checkbox) {
|
||||||
|
cb.checked = false;
|
||||||
|
cb.closest('li')?.classList.remove('is-feature');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkbox.closest('li')?.classList.add('is-feature');
|
||||||
|
if (featureImageInput) featureImageInput.value = url;
|
||||||
|
} else {
|
||||||
|
checkbox.closest('li')?.classList.remove('is-feature');
|
||||||
|
if (featureImageInput) featureImageInput.value = '';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
checkbox.checked = !checkbox.checked;
|
||||||
|
alert(config.strings.feature_image_failed || 'Failed to update feature image.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
contentField.addEventListener('dragover', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
contentField.addEventListener('drop', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!event.dataTransfer.files.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const slugValue = (slugField?.value ?? '').trim();
|
||||||
|
const dateValue = (dateField?.value ?? '').trim();
|
||||||
|
if (slugValue === '' || (config.editorType === 'post' && dateValue === '')) {
|
||||||
|
alert(config.editorType === 'post'
|
||||||
|
? config.strings.save_post_first
|
||||||
|
: config.strings.save_page_first);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of event.dataTransfer.files) {
|
||||||
|
if (!file.type.startsWith('image/')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('image', file);
|
||||||
|
formData.append('slug', slugValue);
|
||||||
|
if (config.editorType === 'post') {
|
||||||
|
formData.append('date', dateValue);
|
||||||
|
} else {
|
||||||
|
formData.append('editor_type', 'page');
|
||||||
|
}
|
||||||
|
formData.append('csrf_token', config.csrfToken || '');
|
||||||
|
|
||||||
|
const response = await fetch((config.basePath || '') + '/admin/upload-image.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(config.strings.upload_failed || 'Upload failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
const redirectUrl = new URL(response.url);
|
||||||
|
const markdown = redirectUrl.searchParams.get('uploaded');
|
||||||
|
if (!markdown) {
|
||||||
|
throw new Error(redirectUrl.searchParams.get('upload_error') || config.strings.upload_failed || 'Upload failed');
|
||||||
|
}
|
||||||
|
insertTextAtCursor(contentField, markdown);
|
||||||
|
} catch (error) {
|
||||||
|
alert(error?.message || config.strings.upload_failed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sidebar Pop-out Toggle Logic
|
||||||
|
const sidebarToggleTab = document.getElementById('sidebar-toggle-tab');
|
||||||
|
const sidebarElement = document.querySelector('.editor-sidebar');
|
||||||
|
|
||||||
|
if (sidebarToggleTab && sidebarElement) {
|
||||||
|
let sidebarOverlay = document.getElementById('editor-sidebar-overlay');
|
||||||
|
if (!sidebarOverlay) {
|
||||||
|
sidebarOverlay = document.createElement('div');
|
||||||
|
sidebarOverlay.id = 'editor-sidebar-overlay';
|
||||||
|
sidebarOverlay.className = 'editor-sidebar-overlay';
|
||||||
|
document.body.appendChild(sidebarOverlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSidebarOpenKey = `${config.editorType || 'editor'}:sidebar-open`;
|
||||||
|
|
||||||
|
const setSidebarOpenState = (isOpen) => {
|
||||||
|
document.body.classList.toggle('editor-sidebar-open', isOpen);
|
||||||
|
localStorage.setItem(isSidebarOpenKey, isOpen ? 'true' : 'false');
|
||||||
|
};
|
||||||
|
|
||||||
|
const savedState = localStorage.getItem(isSidebarOpenKey);
|
||||||
|
const isSmallScreen = window.innerWidth < 1025;
|
||||||
|
|
||||||
|
if (isSmallScreen || savedState === 'false') {
|
||||||
|
setSidebarOpenState(false);
|
||||||
|
} else {
|
||||||
|
setSidebarOpenState(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
sidebarToggleTab.addEventListener('click', () => {
|
||||||
|
document.body.classList.add('sidebar-ready');
|
||||||
|
const isOpen = document.body.classList.contains('editor-sidebar-open');
|
||||||
|
setSidebarOpenState(!isOpen);
|
||||||
|
});
|
||||||
|
|
||||||
|
sidebarOverlay.addEventListener('click', () => {
|
||||||
|
document.body.classList.add('sidebar-ready');
|
||||||
|
setSidebarOpenState(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
24
admin/logout.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/../functions.php';
|
||||||
|
require_setup_redirect();
|
||||||
|
|
||||||
|
start_admin_session();
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
http_response_code(405);
|
||||||
|
$config = load_config();
|
||||||
|
$blogPostsEnabled = $config['enable_blog_posts'] ?? true;
|
||||||
|
header('Location: ' . base_path() . '/admin/' . ($blogPostsEnabled ? 'dashboard.php' : 'content.php'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_csrf();
|
||||||
|
clear_remember_me_cookie();
|
||||||
|
$_SESSION = [];
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
header('Location: ' . base_path() . '/admin/index.php');
|
||||||
|
exit;
|
||||||
125
admin/preview.php
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
verify_csrf();
|
||||||
|
$editorType = trim($_POST['editor_type'] ?? 'post');
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$previewKey = $editorType . ':' . ($slug !== '' ? $slug : 'new');
|
||||||
|
$layoutFields = [];
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if (str_starts_with($key, 'layout_field__')) {
|
||||||
|
$fieldName = substr($key, strlen('layout_field__'));
|
||||||
|
$layoutFields[$fieldName] = trim((string) $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_SESSION['preview'][$previewKey] = [
|
||||||
|
'markdown' => $_POST['markdown'] ?? '',
|
||||||
|
'title' => trim($_POST['title'] ?? ''),
|
||||||
|
'date' => trim($_POST['date'] ?? ''),
|
||||||
|
'tags' => trim($_POST['tags'] ?? ''),
|
||||||
|
'description' => trim($_POST['description'] ?? ''),
|
||||||
|
'layout' => trim($_POST['layout'] ?? ''),
|
||||||
|
'layout_fields' => $layoutFields,
|
||||||
|
'editor_type' => $editorType,
|
||||||
|
'slug' => $slug,
|
||||||
|
'created_at' => time(),
|
||||||
|
];
|
||||||
|
$redirect = base_path() . '/admin/preview.php?type=' . urlencode($editorType);
|
||||||
|
if ($slug !== '') {
|
||||||
|
$redirect .= '&slug=' . urlencode($slug);
|
||||||
|
}
|
||||||
|
header('Location: ' . $redirect);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editorType = trim($_GET['type'] ?? 'post');
|
||||||
|
$slug = trim($_GET['slug'] ?? '');
|
||||||
|
$previewKey = $editorType . ':' . ($slug !== '' ? $slug : 'new');
|
||||||
|
$preview = $_SESSION['preview'][$previewKey] ?? null;
|
||||||
|
$previewTime = $preview ? (int) ($preview['created_at'] ?? 0) : 0;
|
||||||
|
|
||||||
|
$markdown = '';
|
||||||
|
$title = '';
|
||||||
|
$date = '';
|
||||||
|
$tags = '';
|
||||||
|
$description = '';
|
||||||
|
$useSnapshot = $preview !== null;
|
||||||
|
|
||||||
|
if ($slug !== '') {
|
||||||
|
if ($editorType === 'page') {
|
||||||
|
$live = get_page_by_slug($slug, true);
|
||||||
|
} else {
|
||||||
|
$live = get_post_by_slug($slug, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($live) {
|
||||||
|
$path = $live['path'] ?? '';
|
||||||
|
$fileTime = $path && is_file($path) ? (int) filemtime($path) : 0;
|
||||||
|
if ($previewTime <= $fileTime) {
|
||||||
|
$useSnapshot = false;
|
||||||
|
$title = (string) ($live['title'] ?? '');
|
||||||
|
$date = (string) ($live['date'] ?? '');
|
||||||
|
$tags = is_array($live['tags'] ?? null) ? implode(', ', $live['tags']) : '';
|
||||||
|
$description = (string) ($live['description'] ?? '');
|
||||||
|
$markdown = (string) ($live['content'] ?? '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$layout = '';
|
||||||
|
$extraFields = [];
|
||||||
|
|
||||||
|
if ($useSnapshot && $preview) {
|
||||||
|
$markdown = $preview['markdown'] ?? '';
|
||||||
|
$title = trim($preview['title'] ?? '');
|
||||||
|
$date = trim($preview['date'] ?? '');
|
||||||
|
$tags = trim($preview['tags'] ?? '');
|
||||||
|
$description = trim($preview['description'] ?? '');
|
||||||
|
$layout = trim($preview['layout'] ?? '');
|
||||||
|
$extraFields = is_array($preview['layout_fields'] ?? null) ? $preview['layout_fields'] : [];
|
||||||
|
$editorType = trim($preview['editor_type'] ?? $editorType);
|
||||||
|
} elseif (!$useSnapshot && isset($live)) {
|
||||||
|
$layout = (string) ($live['layout'] ?? '');
|
||||||
|
$knownKeys = ['title', 'slug', 'date', 'status', 'tags', 'description', 'content', 'layout', 'path', 'timestamp', 'categories'];
|
||||||
|
foreach ($live as $k => $v) {
|
||||||
|
if (!in_array($k, $knownKeys, true)) {
|
||||||
|
$extraFields[$k] = (string) $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['font_stack'] ?? 'sans');
|
||||||
|
$pageTitle = $title !== '' ? $title : t('admin.editor.preview_title');
|
||||||
|
$metaDescription = $description;
|
||||||
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
|
header('Pragma: no-cache');
|
||||||
|
|
||||||
|
if ($editorType === 'page') {
|
||||||
|
$page = [
|
||||||
|
'title' => $title !== '' ? $title : t('admin.editor.preview_title'),
|
||||||
|
'slug' => $slug,
|
||||||
|
'status' => 'draft',
|
||||||
|
'description' => $description,
|
||||||
|
'include_in_nav' => false,
|
||||||
|
'content' => $markdown,
|
||||||
|
];
|
||||||
|
require __DIR__ . '/../page.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = array_merge($extraFields, [
|
||||||
|
'title' => $title !== '' ? $title : t('admin.editor.preview_title'),
|
||||||
|
'slug' => $slug,
|
||||||
|
'date' => $date,
|
||||||
|
'status' => 'draft',
|
||||||
|
'tags' => $tags !== '' ? array_map('trim', explode(',', $tags)) : [],
|
||||||
|
'description' => $description,
|
||||||
|
'content' => $markdown,
|
||||||
|
'layout' => $layout,
|
||||||
|
]);
|
||||||
|
require __DIR__ . '/../post.php';
|
||||||
78
admin/set-feature-image.php
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_method')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = isset($_POST['csrf_token']) ? (string) $_POST['csrf_token'] : '';
|
||||||
|
$sessionToken = $_SESSION['csrf_token'] ?? '';
|
||||||
|
if ($token === '' || !is_string($sessionToken) || !hash_equals($sessionToken, $token)) {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_csrf')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$editorType = trim($_POST['editor_type'] ?? 'post');
|
||||||
|
$filename = trim($_POST['filename'] ?? '');
|
||||||
|
|
||||||
|
if ($slug === '' || !in_array($editorType, ['post', 'page'], true)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_autosave_slug')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_safe_image_slug($slug)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_image_invalid_path')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($editorType === 'post') {
|
||||||
|
$filepath = find_post_filepath_by_slug($slug);
|
||||||
|
} else {
|
||||||
|
$candidate = PUREBLOG_PAGES_PATH . '/' . $slug . '.md';
|
||||||
|
$filepath = is_file($candidate) ? $candidate : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($filepath === null) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_not_found_' . $editorType)]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($filename !== '') {
|
||||||
|
$cleanFilename = basename($filename);
|
||||||
|
$ext = strtolower(pathinfo($cleanFilename, PATHINFO_EXTENSION));
|
||||||
|
if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif'], true)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_image_invalid_path')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseDir = realpath(PUREBLOG_CONTENT_IMAGES_PATH);
|
||||||
|
if ($baseDir === false) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_image_folder_missing')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$imagePath = PUREBLOG_CONTENT_IMAGES_PATH . '/' . $slug . '/' . $cleanFilename;
|
||||||
|
if (!validate_image_path($baseDir, $imagePath) || !is_file($imagePath)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.error_image_not_found')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$featureValue = '/content/images/' . $slug . '/' . $cleanFilename;
|
||||||
|
} else {
|
||||||
|
$featureValue = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!update_front_matter_field($filepath, 'feature_image', $featureValue)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => t('admin.editor.js_feature_image_failed')]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
84
admin/settings-css.php
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$notice = '';
|
||||||
|
|
||||||
|
$frontCssDir = __DIR__ . '/../content/css';
|
||||||
|
$adminCssDir = __DIR__ . '/../content/css';
|
||||||
|
$frontCssPath = $frontCssDir . '/custom.css';
|
||||||
|
$adminCssPath = $adminCssDir . '/admin-custom.css';
|
||||||
|
$frontCss = is_file($frontCssPath) ? (string) file_get_contents($frontCssPath) : '';
|
||||||
|
$adminCss = is_file($adminCssPath) ? (string) file_get_contents($adminCssPath) : '';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$frontCss = $_POST['front_css'] ?? '';
|
||||||
|
$adminCss = $_POST['admin_css'] ?? '';
|
||||||
|
|
||||||
|
if (!is_dir($frontCssDir) && !mkdir($frontCssDir, 0755, true)) {
|
||||||
|
$errors[] = t('admin.settings.css.error_dir_front');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_dir($adminCssDir) && !mkdir($adminCssDir, 0755, true)) {
|
||||||
|
$errors[] = t('admin.settings.css.error_dir_admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
if (file_put_contents($frontCssPath, $frontCss) === false) {
|
||||||
|
$errors[] = t('admin.settings.css.error_save_front');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_put_contents($adminCssPath, $adminCss) === false) {
|
||||||
|
$errors[] = t('admin.settings.css.error_save_admin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
$notice = t('admin.settings.css.notice_saved');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t('admin.settings.css.page_title');
|
||||||
|
$codeMirror = 'css';
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.settings.css.heading')) ?></h1>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-notices.php'; ?>
|
||||||
|
|
||||||
|
<nav class="admin-actions">
|
||||||
|
<button class="save" type="submit" form="settings-form" aria-label="<?= e(t('admin.settings.nav.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.settings.nav.save')) ?>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<form method="post" id="settings-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.css.section_front')) ?></span>
|
||||||
|
<textarea id="front_css" name="front_css" rows="16" spellcheck="false" placeholder="<?= e(t('admin.settings.css.placeholder_front')) ?>"><?= e($frontCss) ?></textarea>
|
||||||
|
</section>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.css.section_admin')) ?></span>
|
||||||
|
<textarea id="admin_css" name="admin_css" rows="16" spellcheck="false" placeholder="<?= e(t('admin.settings.css.placeholder_admin')) ?>"><?= e($adminCss) ?></textarea>
|
||||||
|
</section>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
const frontCssField = document.getElementById('front_css');
|
||||||
|
const adminCssField = document.getElementById('admin_css');
|
||||||
|
|
||||||
|
if (typeof window.createSyntaxEditor === 'function') {
|
||||||
|
window.createSyntaxEditor(frontCssField, 'css');
|
||||||
|
window.createSyntaxEditor(adminCssField, 'css');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
526
admin/settings-site.php
Normal file
|
|
@ -0,0 +1,526 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
if (isset($_GET['delete_asset']) && in_array($_GET['delete_asset'], ['favicon', 'apple_touch_icon', 'og_image', 'sidebar_logo'], true)) {
|
||||||
|
$token = $_GET['csrf_token'] ?? '';
|
||||||
|
$sessionToken = $_SESSION['csrf_token'] ?? '';
|
||||||
|
if ($token === '' || !is_string($sessionToken) || !hash_equals($sessionToken, $token)) {
|
||||||
|
http_response_code(403);
|
||||||
|
exit('Invalid CSRF token.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$asset = $_GET['delete_asset'];
|
||||||
|
if (isset($config['assets'][$asset])) {
|
||||||
|
$assetPath = $config['assets'][$asset];
|
||||||
|
if ($assetPath !== '') {
|
||||||
|
$filePath = PUREBLOG_BASE_PATH . $assetPath;
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
if (validate_image_path(PUREBLOG_CONTENT_IMAGES_PATH, $filePath)) {
|
||||||
|
@unlink($filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($config['assets'][$asset]);
|
||||||
|
if (save_config($config)) {
|
||||||
|
$_SESSION['admin_action_flash'] = ['ok' => true, 'message' => t('admin.settings.site.notice_updated')];
|
||||||
|
} else {
|
||||||
|
$_SESSION['admin_action_flash'] = ['ok' => false, 'message' => t('admin.settings.site.error_save')];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header('Location: ' . base_path() . '/admin/settings-site.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$notice = '';
|
||||||
|
$hiddenBlogValue = '__hidden__';
|
||||||
|
$pages = get_all_pages(true);
|
||||||
|
$pageOptions = array_values(array_filter($pages, fn($page) => ($page['slug'] ?? '') !== ''));
|
||||||
|
$pageSlugLookup = array_fill_keys(array_map(fn($page) => $page['slug'], $pageOptions), true);
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['download_backup'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$backupResult = create_site_backup_zip();
|
||||||
|
if ($backupResult['ok'] ?? false) {
|
||||||
|
$zipPath = (string) $backupResult['path'];
|
||||||
|
$zipName = (string) $backupResult['filename'];
|
||||||
|
try {
|
||||||
|
while (ob_get_level() > 0) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
header('Content-Type: application/zip');
|
||||||
|
header('Content-Disposition: attachment; filename="' . $zipName . '"');
|
||||||
|
header('Content-Length: ' . (string) filesize($zipPath));
|
||||||
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
|
readfile($zipPath);
|
||||||
|
} finally {
|
||||||
|
@unlink($zipPath);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$errors[] = (string) ($backupResult['error'] ?? t('admin.settings.site.error_backup_zip'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id']) && !isset($_POST['download_backup'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$siteTitle = trim($_POST['site_title'] ?? '');
|
||||||
|
$siteTagline = trim($_POST['site_tagline'] ?? '');
|
||||||
|
$siteDescription = trim($_POST['site_description'] ?? '');
|
||||||
|
$siteEmail = trim($_POST['site_email'] ?? '');
|
||||||
|
$customNav = trim($_POST['custom_nav'] ?? '');
|
||||||
|
$customNavOnly = !empty($_POST['custom_nav_only']);
|
||||||
|
$customRoutes = trim($_POST['custom_routes'] ?? '');
|
||||||
|
$headInjectPage = trim($_POST['head_inject_page'] ?? '');
|
||||||
|
$headInjectPost = trim($_POST['head_inject_post'] ?? '');
|
||||||
|
$footerInjectPage = trim($_POST['footer_inject_page'] ?? '');
|
||||||
|
$footerInjectPost = trim($_POST['footer_inject_post'] ?? '');
|
||||||
|
$postsPerPage = (int) ($_POST['posts_per_page'] ?? 20);
|
||||||
|
$searchExcerptLength = max(0, (int) ($_POST['search_excerpt_length'] ?? 2500));
|
||||||
|
$searchIncludePages = !empty($_POST['search_include_pages']);
|
||||||
|
$language = trim($_POST['language'] ?? '');
|
||||||
|
$timezone = trim($_POST['timezone'] ?? '');
|
||||||
|
$dateFormat = trim($_POST['date_format'] ?? '');
|
||||||
|
$baseUrl = trim($_POST['base_url'] ?? '');
|
||||||
|
$homepageSlug = trim($_POST['homepage_slug'] ?? '');
|
||||||
|
$blogPageSlug = trim($_POST['blog_page_slug'] ?? '');
|
||||||
|
$searchPageSlug = trim($_POST['search_page_slug'] ?? '');
|
||||||
|
$ogImagePreferred = trim($_POST['og_image_preferred'] ?? 'banner');
|
||||||
|
$showReadingTime = !empty($_POST['show_reading_time']);
|
||||||
|
$cacheEnabled = !empty($_POST['cache_enabled']);
|
||||||
|
$rssttl = max(0, (int) ($_POST['rss_ttl'] ?? 3600));
|
||||||
|
$adminHomepage = in_array($_POST['admin_homepage'] ?? '', ['dashboard', 'content'], true) ? $_POST['admin_homepage'] : 'dashboard';
|
||||||
|
$adminHideDashboard = $adminHomepage === 'content' && !empty($_POST['admin_hide_dashboard']);
|
||||||
|
$enableBlogPosts = ($blogPageSlug === $hiddenBlogValue) ? !empty($_POST['enable_blog_posts']) : true;
|
||||||
|
$purecommentsEnabled = !empty($_POST['purecomments_enabled']);
|
||||||
|
$purecommentsUrl = trim($_POST['purecomments_url'] ?? '');
|
||||||
|
$purecommentsAutoload = !empty($_POST['purecomments_autoload']);
|
||||||
|
|
||||||
|
if ($siteTitle === '') {
|
||||||
|
$errors[] = t('admin.settings.site.error_title');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($postsPerPage < 1 || $postsPerPage > 100) {
|
||||||
|
$errors[] = t('admin.settings.site.error_posts_per_page');
|
||||||
|
}
|
||||||
|
if ($timezone === '' || !in_array($timezone, DateTimeZone::listIdentifiers(), true)) {
|
||||||
|
$errors[] = t('admin.settings.site.error_timezone');
|
||||||
|
}
|
||||||
|
if ($dateFormat === '') {
|
||||||
|
$errors[] = t('admin.settings.site.error_date_format');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($homepageSlug !== '' && !isset($pageSlugLookup[$homepageSlug])) {
|
||||||
|
$errors[] = t('admin.settings.site.error_homepage');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($blogPageSlug !== '' && $blogPageSlug !== $hiddenBlogValue && !isset($pageSlugLookup[$blogPageSlug])) {
|
||||||
|
$errors[] = t('admin.settings.site.error_blog_page');
|
||||||
|
}
|
||||||
|
if ($searchPageSlug !== '' && !isset($pageSlugLookup[$searchPageSlug])) {
|
||||||
|
$errors[] = t('admin.settings.site.error_search_page');
|
||||||
|
}
|
||||||
|
if (!in_array($ogImagePreferred, ['banner', 'square'], true)) {
|
||||||
|
$errors[] = t('admin.settings.site.error_og_format');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($purecommentsEnabled) {
|
||||||
|
if ($purecommentsUrl === '') {
|
||||||
|
$errors[] = t('admin.settings.site.error_purecomments_url');
|
||||||
|
} elseif (!filter_var($purecommentsUrl, FILTER_VALIDATE_URL)) {
|
||||||
|
$errors[] = t('admin.settings.site.error_purecomments_url_invalid');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
$config['site_title'] = $siteTitle;
|
||||||
|
$config['site_tagline'] = $siteTagline;
|
||||||
|
$config['site_description'] = $siteDescription;
|
||||||
|
$config['site_email'] = $siteEmail;
|
||||||
|
$config['custom_nav'] = $customNav;
|
||||||
|
$config['custom_nav_only'] = $customNavOnly;
|
||||||
|
$config['custom_routes'] = $customRoutes;
|
||||||
|
$config['head_inject_page'] = $headInjectPage;
|
||||||
|
$config['head_inject_post'] = $headInjectPost;
|
||||||
|
$config['footer_inject_page'] = $footerInjectPage;
|
||||||
|
$config['footer_inject_post'] = $footerInjectPost;
|
||||||
|
$config['posts_per_page'] = $postsPerPage;
|
||||||
|
$config['search_excerpt_length'] = $searchExcerptLength;
|
||||||
|
$config['search_include_pages'] = $searchIncludePages;
|
||||||
|
$config['language'] = $language !== '' ? $language : 'en';
|
||||||
|
$config['timezone'] = $timezone;
|
||||||
|
$config['date_format'] = $dateFormat;
|
||||||
|
$config['show_reading_time'] = $showReadingTime;
|
||||||
|
$config['base_url'] = $baseUrl;
|
||||||
|
$config['homepage_slug'] = $homepageSlug;
|
||||||
|
$config['blog_page_slug'] = $blogPageSlug;
|
||||||
|
$config['search_page_slug'] = $searchPageSlug;
|
||||||
|
$config['cache']['enabled'] = $cacheEnabled;
|
||||||
|
$config['cache']['rss_ttl'] = $rssttl;
|
||||||
|
$config['admin_homepage'] = $adminHomepage;
|
||||||
|
$config['admin_hide_dashboard'] = $adminHideDashboard;
|
||||||
|
$config['enable_blog_posts'] = $enableBlogPosts;
|
||||||
|
$config['community']['purecomments_enabled'] = $purecommentsEnabled;
|
||||||
|
$config['community']['purecomments_url'] = rtrim($purecommentsUrl, '/');
|
||||||
|
$config['community']['purecomments_autoload'] = $purecommentsAutoload;
|
||||||
|
|
||||||
|
if (!isset($config['assets'])) {
|
||||||
|
$config['assets'] = ['favicon' => '', 'apple_touch_icon' => '', 'og_image' => '', 'og_image_preferred' => 'banner', 'sidebar_logo' => ''];
|
||||||
|
}
|
||||||
|
$config['assets']['og_image_preferred'] = $ogImagePreferred;
|
||||||
|
|
||||||
|
$assetDir = PUREBLOG_CONTENT_IMAGES_PATH;
|
||||||
|
if (!is_dir($assetDir)) {
|
||||||
|
mkdir($assetDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$allowedImageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif'];
|
||||||
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||||
|
|
||||||
|
if (!empty($_FILES['favicon']['name']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$mimeType = $finfo->file($_FILES['favicon']['tmp_name']) ?: '';
|
||||||
|
if (in_array($mimeType, $allowedImageTypes, true)) {
|
||||||
|
$name = basename($_FILES['favicon']['name']);
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = preg_replace('/[^a-z0-9._-]/', '-', $name) ?? $name;
|
||||||
|
$name = preg_replace('/-+/', '-', $name) ?? $name;
|
||||||
|
$name = trim($name, '-');
|
||||||
|
if ($name !== '') {
|
||||||
|
$dest = $assetDir . '/' . $name;
|
||||||
|
if (move_uploaded_file($_FILES['favicon']['tmp_name'], $dest)) {
|
||||||
|
$config['assets']['favicon'] = '/content/images/' . $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.editor.error_upload_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_FILES['apple_touch_icon']['name']) && $_FILES['apple_touch_icon']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$mimeType = $finfo->file($_FILES['apple_touch_icon']['tmp_name']) ?: '';
|
||||||
|
if ($mimeType === 'image/png') {
|
||||||
|
$name = basename($_FILES['apple_touch_icon']['name']);
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = preg_replace('/[^a-z0-9._-]/', '-', $name) ?? $name;
|
||||||
|
$name = preg_replace('/-+/', '-', $name) ?? $name;
|
||||||
|
$name = trim($name, '-');
|
||||||
|
if ($name !== '') {
|
||||||
|
$dest = $assetDir . '/' . $name;
|
||||||
|
if (move_uploaded_file($_FILES['apple_touch_icon']['tmp_name'], $dest)) {
|
||||||
|
$config['assets']['apple_touch_icon'] = '/content/images/' . $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.site.error_apple_touch_icon_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_FILES['og_image']['name']) && $_FILES['og_image']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$mimeType = $finfo->file($_FILES['og_image']['tmp_name']) ?: '';
|
||||||
|
if (in_array($mimeType, $allowedImageTypes, true)) {
|
||||||
|
$name = basename($_FILES['og_image']['name']);
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = preg_replace('/[^a-z0-9._-]/', '-', $name) ?? $name;
|
||||||
|
$name = preg_replace('/-+/', '-', $name) ?? $name;
|
||||||
|
$name = trim($name, '-');
|
||||||
|
if ($name !== '') {
|
||||||
|
$dest = $assetDir . '/' . $name;
|
||||||
|
if (move_uploaded_file($_FILES['og_image']['tmp_name'], $dest)) {
|
||||||
|
$config['assets']['og_image'] = '/content/images/' . $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.editor.error_upload_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_FILES['sidebar_logo']['name']) && $_FILES['sidebar_logo']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$mimeType = $finfo->file($_FILES['sidebar_logo']['tmp_name']) ?: '';
|
||||||
|
if (in_array($mimeType, $allowedImageTypes, true)) {
|
||||||
|
$name = basename($_FILES['sidebar_logo']['name']);
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = preg_replace('/[^a-z0-9._-]/', '-', $name) ?? $name;
|
||||||
|
$name = preg_replace('/-+/', '-', $name) ?? $name;
|
||||||
|
$name = trim($name, '-');
|
||||||
|
if ($name !== '') {
|
||||||
|
$dest = $assetDir . '/' . $name;
|
||||||
|
if (move_uploaded_file($_FILES['sidebar_logo']['tmp_name'], $dest)) {
|
||||||
|
$config['assets']['sidebar_logo'] = '/content/images/' . $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.editor.error_upload_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
build_search_index();
|
||||||
|
$notice = t('admin.settings.site.notice_updated');
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.site.error_save');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t('admin.settings.site.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.settings.site.heading')) ?></h1>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-notices.php'; ?>
|
||||||
|
|
||||||
|
<nav class="admin-actions">
|
||||||
|
<button class="save" type="submit" form="settings-form" aria-label="<?= e(t('admin.settings.nav.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.settings.nav.save')) ?>
|
||||||
|
</button>
|
||||||
|
<form method="post" class="inline-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button type="submit" name="download_backup" value="1" aria-label="<?= e(t('admin.settings.site.download_backup')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-download"></use></svg>
|
||||||
|
<?= e(t('admin.settings.site.download_backup')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<form method="post" enctype="multipart/form-data" id="settings-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.section_title')) ?></span>
|
||||||
|
<label for="site_title"><?= e(t('admin.settings.site.site_title')) ?></label>
|
||||||
|
<input type="text" id="site_title" name="site_title" value="<?= e($config['site_title']) ?>" required>
|
||||||
|
|
||||||
|
<label for="site_tagline"><?= e(t('admin.settings.site.tagline')) ?></label>
|
||||||
|
<input type="text" id="site_tagline" name="site_tagline" value="<?= e($config['site_tagline']) ?>">
|
||||||
|
|
||||||
|
<label for="site_description"><?= e(t('admin.settings.site.description')) ?></label>
|
||||||
|
<textarea id="site_description" name="site_description" rows="4"><?= e($config['site_description'] ?? '') ?></textarea>
|
||||||
|
|
||||||
|
<label for="site_email"><?= e(t('admin.settings.site.email')) ?></label>
|
||||||
|
<input type="email" id="site_email" name="site_email" value="<?= e($config['site_email'] ?? '') ?>" placeholder="you@example.com">
|
||||||
|
|
||||||
|
<label for="posts_per_page"><?= e(t('admin.settings.site.posts_per_page')) ?></label>
|
||||||
|
<input type="number" id="posts_per_page" name="posts_per_page" min="1" max="100" value="<?= e((string) ($config['posts_per_page'] ?? 20)) ?>">
|
||||||
|
|
||||||
|
<label for="search_excerpt_length"><?= e(t('admin.settings.site.search_excerpt_length')) ?></label>
|
||||||
|
<input type="number" id="search_excerpt_length" name="search_excerpt_length" min="0" value="<?= e((string) ($config['search_excerpt_length'] ?? 2500)) ?>">
|
||||||
|
<p class="tip"><?= e(t('admin.settings.site.search_excerpt_length_tip')) ?></p>
|
||||||
|
|
||||||
|
<label class="inline-checkbox" for="search_include_pages">
|
||||||
|
<input type="checkbox" id="search_include_pages" name="search_include_pages"<?= ($config['search_include_pages'] ?? true) ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.search_include_pages')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$availableLanguages = lang_available();
|
||||||
|
$currentLanguage = (string) ($config['language'] ?? 'en');
|
||||||
|
if (!isset($availableLanguages[$currentLanguage]) && $currentLanguage !== '') {
|
||||||
|
$availableLanguages[$currentLanguage] = $currentLanguage;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<label for="language"><?= e(t('admin.settings.site.language')) ?></label>
|
||||||
|
<select id="language" name="language">
|
||||||
|
<?php foreach ($availableLanguages as $langCode => $langName): ?>
|
||||||
|
<option value="<?= e($langCode) ?>"<?= $langCode === $currentLanguage ? ' selected' : '' ?>><?= e($langName) ?> (<?= e($langCode) ?>)</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="timezone"><?= e(t('admin.settings.site.timezone')) ?> <span class="tip">(<a href="https://www.php.net/manual/en/timezones.php" target="_blank" rel="noopener noreferrer"><?= e(t('admin.settings.site.tip_timezone_link')) ?></a>)</span></label>
|
||||||
|
<input type="text" id="timezone" name="timezone" value="<?= e((string) ($config['timezone'] ?? date_default_timezone_get())) ?>" placeholder="UTC" required>
|
||||||
|
|
||||||
|
<label for="date_format"><?= e(t('admin.settings.site.date_format')) ?> <span class="tip">(<a href="https://www.php.net/manual/en/datetime.format.php" target="_blank" rel="noopener noreferrer"><?= e(t('admin.settings.site.tip_date_format_link')) ?></a>)</span></label>
|
||||||
|
<input type="text" id="date_format" name="date_format" value="<?= e((string) ($config['date_format'] ?? 'F j, Y')) ?>" placeholder="F j, Y" required>
|
||||||
|
|
||||||
|
<label class="inline-checkbox" for="show_reading_time">
|
||||||
|
<input type="checkbox" id="show_reading_time" name="show_reading_time"<?= !empty($config['show_reading_time']) ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.show_reading_time')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="homepage_slug"><?= e(t('admin.settings.site.homepage')) ?></label>
|
||||||
|
<select id="homepage_slug" name="homepage_slug">
|
||||||
|
<option value=""><?= e(t('admin.settings.site.homepage_default')) ?></option>
|
||||||
|
<?php foreach ($pageOptions as $pageOption): ?>
|
||||||
|
<option value="<?= e($pageOption['slug']) ?>"<?= ($config['homepage_slug'] ?? '') === $pageOption['slug'] ? ' selected' : '' ?>>
|
||||||
|
<?= e($pageOption['title']) ?> (<?= e($pageOption['slug']) ?>)
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<label for="blog_page_slug"><?= e(t('admin.settings.site.blog_page')) ?></label>
|
||||||
|
<select id="blog_page_slug" name="blog_page_slug">
|
||||||
|
<option value=""><?= e(t('admin.settings.site.blog_use_homepage')) ?></option>
|
||||||
|
<option value="<?= e($hiddenBlogValue) ?>"<?= ($config['blog_page_slug'] ?? '') === $hiddenBlogValue ? ' selected' : '' ?>><?= e(t('admin.settings.site.blog_hidden')) ?></option>
|
||||||
|
<?php foreach ($pageOptions as $pageOption): ?>
|
||||||
|
<option value="<?= e($pageOption['slug']) ?>"<?= ($config['blog_page_slug'] ?? '') === $pageOption['slug'] ? ' selected' : '' ?>>
|
||||||
|
<?= e($pageOption['title']) ?> (<?= e($pageOption['slug']) ?>)
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<div id="enable_blog_posts_container" style="<?= ($config['blog_page_slug'] ?? '') === $hiddenBlogValue ? '' : 'display: none;' ?> margin-top: -0.75rem; margin-bottom: 1.5rem;">
|
||||||
|
<label class="inline-checkbox" for="enable_blog_posts">
|
||||||
|
<input type="checkbox" id="enable_blog_posts" name="enable_blog_posts"<?= ($config['enable_blog_posts'] ?? true) ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.enable_blog_posts')) ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label for="search_page_slug"><?= e(t('admin.settings.site.search_page')) ?></label>
|
||||||
|
<select id="search_page_slug" name="search_page_slug">
|
||||||
|
<option value=""><?= e(t('admin.settings.site.search_page_none')) ?></option>
|
||||||
|
<?php foreach ($pageOptions as $pageOption): ?>
|
||||||
|
<option value="<?= e($pageOption['slug']) ?>"<?= ($config['search_page_slug'] ?? 'search') === $pageOption['slug'] ? ' selected' : '' ?>>
|
||||||
|
<?= e($pageOption['title']) ?> (<?= e($pageOption['slug']) ?>)
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="base_url"><?= e(t('admin.settings.site.base_url')) ?></label>
|
||||||
|
<input type="text" id="base_url" name="base_url" value="<?= e($config['base_url']) ?>">
|
||||||
|
|
||||||
|
<label for="favicon"><?= e(t('admin.settings.site.favicon')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_favicon')) ?>)</span></label>
|
||||||
|
<input type="file" id="favicon" name="favicon" accept="image/*">
|
||||||
|
<?php if (!empty($config['assets']['favicon'])): ?>
|
||||||
|
<p class="current-image"><?= e(t('admin.settings.site.current')) ?>: <a href="<?= e($config['assets']['favicon']) ?>" target="_blank" rel="noopener noreferrer"><?= e($config['assets']['favicon']) ?></a> <a href="?delete_asset=favicon&csrf_token=<?= urlencode(csrf_token()) ?>" class="link-button delete" onclick="return confirm('<?= e(t('admin.images.delete_confirm')) ?>');"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></a></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<label for="apple_touch_icon"><?= e(t('admin.settings.site.apple_touch_icon')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_apple_touch_icon')) ?>)</span></label>
|
||||||
|
<input type="file" id="apple_touch_icon" name="apple_touch_icon" accept="image/png,.png">
|
||||||
|
<?php if (!empty($config['assets']['apple_touch_icon'])): ?>
|
||||||
|
<p class="current-image"><?= e(t('admin.settings.site.current')) ?>: <a href="<?= e($config['assets']['apple_touch_icon']) ?>" target="_blank" rel="noopener noreferrer"><?= e($config['assets']['apple_touch_icon']) ?></a> <a href="?delete_asset=apple_touch_icon&csrf_token=<?= urlencode(csrf_token()) ?>" class="link-button delete" onclick="return confirm('<?= e(t('admin.images.delete_confirm')) ?>');"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></a></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<label for="og_image"><?= e(t('admin.settings.site.og_image')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_og_image')) ?>)</span></label>
|
||||||
|
<input type="file" id="og_image" name="og_image" accept="image/*">
|
||||||
|
<p class="tip"><?= e(t('admin.settings.site.tip_og_image_dynamic')) ?> <a href="https://docs.pureblog.org/open-graph-images/" target="_blank" rel="noopener noreferrer"><?= e(t('admin.settings.site.tip_og_image_doc_link')) ?></a>.</p>
|
||||||
|
<?php if (!empty($config['assets']['og_image'])): ?>
|
||||||
|
<p class="current-image"><?= e(t('admin.settings.site.current')) ?>: <a href="<?= e($config['assets']['og_image']) ?>" target="_blank" rel="noopener noreferrer"><?= e($config['assets']['og_image']) ?></a> <a href="?delete_asset=og_image&csrf_token=<?= urlencode(csrf_token()) ?>" class="link-button delete" onclick="return confirm('<?= e(t('admin.images.delete_confirm')) ?>');"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></a></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<label for="og_image_preferred"><?= e(t('admin.settings.site.og_image_format')) ?></label>
|
||||||
|
<select id="og_image_preferred" name="og_image_preferred">
|
||||||
|
<option value="banner"<?= ($config['assets']['og_image_preferred'] ?? 'banner') === 'banner' ? ' selected' : '' ?>><?= e(t('admin.settings.site.og_banner')) ?></option>
|
||||||
|
<option value="square"<?= ($config['assets']['og_image_preferred'] ?? 'banner') === 'square' ? ' selected' : '' ?>><?= e(t('admin.settings.site.og_square')) ?></option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="sidebar_logo"><?= e(t('admin.settings.site.sidebar_logo')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_sidebar_logo')) ?>)</span></label>
|
||||||
|
<input type="file" id="sidebar_logo" name="sidebar_logo" accept="image/*">
|
||||||
|
<?php if (!empty($config['assets']['sidebar_logo'])): ?>
|
||||||
|
<p class="current-image"><?= e(t('admin.settings.site.current')) ?>: <a href="<?= e($config['assets']['sidebar_logo']) ?>" target="_blank" rel="noopener noreferrer"><?= e($config['assets']['sidebar_logo']) ?></a> <a href="?delete_asset=sidebar_logo&csrf_token=<?= urlencode(csrf_token()) ?>" class="link-button delete" onclick="return confirm('<?= e(t('admin.images.delete_confirm')) ?>');"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.editor.delete')) ?></a></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<label for="custom_nav"><?= e(t('admin.settings.site.custom_nav')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_one_per_line')) ?>)</span></label>
|
||||||
|
<textarea id="custom_nav" name="custom_nav" rows="4" placeholder="GitHub | https://github.com/you Projects | /projects"><?= e($config['custom_nav'] ?? '') ?></textarea>
|
||||||
|
|
||||||
|
<label class="inline-checkbox" for="custom_nav_only" style="margin-top: -0.5rem; margin-bottom: 1.25rem;">
|
||||||
|
<input type="checkbox" id="custom_nav_only" name="custom_nav_only"<?= !empty($config['custom_nav_only']) ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.custom_nav_only')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="custom_routes"><?= e(t('admin.settings.site.custom_routes')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_one_per_line')) ?>)</span></label>
|
||||||
|
<textarea id="custom_routes" name="custom_routes" rows="4" placeholder="/archive | /content/includes/archive.php /reading | reading.php"><?= e($config['custom_routes'] ?? '') ?></textarea>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.community_section')) ?></span>
|
||||||
|
<label class="inline-checkbox" for="purecomments_enabled">
|
||||||
|
<input type="checkbox" id="purecomments_enabled" name="purecomments_enabled"<?= !empty($config['community']['purecomments_enabled']) ? ' checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.purecomments_enable')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div id="purecomments_url_container" style="<?= !empty($config['community']['purecomments_enabled']) ? '' : 'display: none;' ?> margin-top: -0.75rem; margin-bottom: 1.5rem;">
|
||||||
|
<label for="purecomments_url"><?= e(t('admin.settings.site.purecomments_url')) ?></label>
|
||||||
|
<input type="url" id="purecomments_url" name="purecomments_url" value="<?= e($config['community']['purecomments_url'] ?? '') ?>" placeholder="https://comments.example.com"<?= !empty($config['community']['purecomments_enabled']) ? ' required' : ' disabled' ?>>
|
||||||
|
|
||||||
|
<label class="inline-checkbox" for="purecomments_autoload" style="margin-top: -0.5rem;" title="<?= e(t('admin.settings.site.purecomments_autoload_tooltip')) ?>">
|
||||||
|
<input type="checkbox" id="purecomments_autoload" name="purecomments_autoload"<?= !empty($config['community']['purecomments_autoload']) ? ' checked' : '' ?><?= !empty($config['community']['purecomments_enabled']) ? '' : ' disabled' ?>>
|
||||||
|
<?= e(t('admin.settings.site.purecomments_autoload')) ?>
|
||||||
|
<abbr title="<?= e(t('admin.settings.site.purecomments_autoload_tooltip')) ?>">(?)</abbr>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.header_injects')) ?></span>
|
||||||
|
<label for="head_inject_page"><?= e(t('admin.settings.site.head_inject_page_label')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_optional')) ?>)</span></label>
|
||||||
|
<textarea id="head_inject_page" name="head_inject_page" rows="6" placeholder="<meta name="x-custom" content="value">"><?= e($config['head_inject_page'] ?? '') ?></textarea>
|
||||||
|
|
||||||
|
<label for="head_inject_post"><?= e(t('admin.settings.site.head_inject_post_label')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_optional')) ?>)</span></label>
|
||||||
|
<textarea id="head_inject_post" name="head_inject_post" rows="6" placeholder="<link rel="stylesheet" href="/content/css/comments.css">"><?= e($config['head_inject_post'] ?? '') ?></textarea>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.footer_injects')) ?></span>
|
||||||
|
<label for="footer_inject_page"><?= e(t('admin.settings.site.footer_inject_page_label')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_optional')) ?>)</span></label>
|
||||||
|
<textarea id="footer_inject_page" name="footer_inject_page" rows="6" placeholder="<script src="/assets/js/page-only.js" defer></script>"><?= e($config['footer_inject_page'] ?? '') ?></textarea>
|
||||||
|
|
||||||
|
<label for="footer_inject_post"><?= e(t('admin.settings.site.footer_inject_post_label')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_optional')) ?>)</span></label>
|
||||||
|
<textarea id="footer_inject_post" name="footer_inject_post" rows="6" placeholder="<script src="/assets/js/post-only.js" defer></script>"><?= e($config['footer_inject_post'] ?? '') ?></textarea>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.admin_ui_section')) ?></span>
|
||||||
|
<label for="admin_homepage"><?= e(t('admin.settings.site.admin_homepage')) ?></label>
|
||||||
|
<select id="admin_homepage" name="admin_homepage">
|
||||||
|
<option value="dashboard"<?= ($config['admin_homepage'] ?? 'dashboard') === 'dashboard' ? ' selected' : '' ?>><?= e(t('admin.settings.site.admin_homepage_dashboard')) ?></option>
|
||||||
|
<option value="content"<?= ($config['admin_homepage'] ?? 'dashboard') === 'content' ? ' selected' : '' ?>><?= e(t('admin.settings.site.admin_homepage_content')) ?></option>
|
||||||
|
</select>
|
||||||
|
<label class="inline-checkbox" for="admin_hide_dashboard">
|
||||||
|
<input type="checkbox" id="admin_hide_dashboard" name="admin_hide_dashboard"<?= !empty($config['admin_hide_dashboard']) ? ' checked' : '' ?><?= ($config['admin_homepage'] ?? 'dashboard') !== 'content' ? ' disabled' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.admin_hide_dashboard')) ?>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.site.cache_section')) ?></span>
|
||||||
|
<label class="inline-checkbox" for="cache_enabled">
|
||||||
|
<input type="checkbox" id="cache_enabled" name="cache_enabled" <?= !empty($config['cache']['enabled']) ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.site.cache_enable')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="rss_ttl"><?= e(t('admin.settings.site.rss_ttl')) ?> <span class="tip">(<?= e(t('admin.settings.site.tip_rss_ttl')) ?>)</span></label>
|
||||||
|
<input type="number" id="rss_ttl" name="rss_ttl" min="0" value="<?= e((string) ($config['cache']['rss_ttl'] ?? 3600)) ?>">
|
||||||
|
</section>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
const adminHomepageSelect = document.getElementById('admin_homepage');
|
||||||
|
const hideDashboardCheckbox = document.getElementById('admin_hide_dashboard');
|
||||||
|
adminHomepageSelect.addEventListener('change', function () {
|
||||||
|
hideDashboardCheckbox.disabled = this.value !== 'content';
|
||||||
|
if (hideDashboardCheckbox.disabled) hideDashboardCheckbox.checked = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
const blogPageSlugSelect = document.getElementById('blog_page_slug');
|
||||||
|
const enableBlogPostsContainer = document.getElementById('enable_blog_posts_container');
|
||||||
|
const enableBlogPostsCheckbox = document.getElementById('enable_blog_posts');
|
||||||
|
blogPageSlugSelect.addEventListener('change', function () {
|
||||||
|
if (this.value === '__hidden__') {
|
||||||
|
enableBlogPostsContainer.style.display = '';
|
||||||
|
} else {
|
||||||
|
enableBlogPostsContainer.style.display = 'none';
|
||||||
|
enableBlogPostsCheckbox.checked = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const pureCommentsEnabledCheckbox = document.getElementById('purecomments_enabled');
|
||||||
|
const pureCommentsUrlContainer = document.getElementById('purecomments_url_container');
|
||||||
|
const pureCommentsUrlInput = document.getElementById('purecomments_url');
|
||||||
|
const pureCommentsAutoloadCheckbox = document.getElementById('purecomments_autoload');
|
||||||
|
pureCommentsEnabledCheckbox.addEventListener('change', function () {
|
||||||
|
if (this.checked) {
|
||||||
|
pureCommentsUrlContainer.style.display = '';
|
||||||
|
pureCommentsUrlInput.disabled = false;
|
||||||
|
pureCommentsUrlInput.required = true;
|
||||||
|
if (pureCommentsAutoloadCheckbox) pureCommentsAutoloadCheckbox.disabled = false;
|
||||||
|
} else {
|
||||||
|
pureCommentsUrlContainer.style.display = 'none';
|
||||||
|
pureCommentsUrlInput.disabled = true;
|
||||||
|
pureCommentsUrlInput.required = false;
|
||||||
|
if (pureCommentsAutoloadCheckbox) pureCommentsAutoloadCheckbox.disabled = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
468
admin/settings-theme.php
Normal file
|
|
@ -0,0 +1,468 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$notice = '';
|
||||||
|
|
||||||
|
if (isset($_SESSION['admin_theme_notice'])) {
|
||||||
|
$notice = (string) $_SESSION['admin_theme_notice'];
|
||||||
|
unset($_SESSION['admin_theme_notice']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
|
if (isset($_POST['apply_theme_id'])) {
|
||||||
|
$themeId = trim((string) $_POST['apply_theme_id']);
|
||||||
|
$theme = get_theme_by_id($themeId);
|
||||||
|
if ($theme) {
|
||||||
|
if (apply_theme_to_config($theme)) {
|
||||||
|
$notice = t('admin.settings.theme.notice_theme_applied');
|
||||||
|
$config = load_config(true);
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.theme.error_save');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_not_found');
|
||||||
|
}
|
||||||
|
} elseif (isset($_POST['delete_theme_filename'])) {
|
||||||
|
$filename = trim((string) $_POST['delete_theme_filename']);
|
||||||
|
if (delete_theme_file($filename)) {
|
||||||
|
$notice = t('admin.settings.theme.notice_theme_deleted');
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_delete');
|
||||||
|
}
|
||||||
|
} elseif ($action === 'create_theme') {
|
||||||
|
$themeName = trim((string) ($_POST['new_theme_name'] ?? ''));
|
||||||
|
if ($themeName === '') {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_name');
|
||||||
|
} else {
|
||||||
|
$lightRaw = [
|
||||||
|
'bg' => trim((string) ($_POST['new_bg'] ?? '')),
|
||||||
|
'text' => trim((string) ($_POST['new_text'] ?? '')),
|
||||||
|
'accent' => trim((string) ($_POST['new_accent'] ?? '')),
|
||||||
|
'border' => trim((string) ($_POST['new_border'] ?? '')),
|
||||||
|
'accent_bg' => trim((string) ($_POST['new_accent_bg'] ?? '')),
|
||||||
|
];
|
||||||
|
$darkRaw = [
|
||||||
|
'bg' => trim((string) ($_POST['new_bg_dark'] ?? '')),
|
||||||
|
'text' => trim((string) ($_POST['new_text_dark'] ?? '')),
|
||||||
|
'accent' => trim((string) ($_POST['new_accent_dark'] ?? '')),
|
||||||
|
'border' => trim((string) ($_POST['new_border_dark'] ?? '')),
|
||||||
|
'accent_bg' => trim((string) ($_POST['new_accent_bg_dark'] ?? '')),
|
||||||
|
];
|
||||||
|
|
||||||
|
$lightFilled = count(array_filter($lightRaw, fn($v) => $v !== ''));
|
||||||
|
$darkFilled = count(array_filter($darkRaw, fn($v) => $v !== ''));
|
||||||
|
|
||||||
|
if ($lightFilled === 0 && $darkFilled === 0) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_empty');
|
||||||
|
} elseif ($lightFilled > 0 && $lightFilled < 5) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_light_incomplete');
|
||||||
|
} elseif ($darkFilled > 0 && $darkFilled < 5) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_dark_incomplete');
|
||||||
|
} else {
|
||||||
|
$light = $lightFilled === 5 ? $lightRaw : null;
|
||||||
|
$dark = $darkFilled === 5 ? $darkRaw : null;
|
||||||
|
|
||||||
|
$res = save_theme_json($themeName, $light, $dark);
|
||||||
|
if (!empty($res['ok'])) {
|
||||||
|
$notice = t('admin.settings.theme.notice_theme_created');
|
||||||
|
} else {
|
||||||
|
$errors[] = $res['error'] ?? t('admin.settings.theme.error_theme_save');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($action === 'import_theme') {
|
||||||
|
if (!empty($_FILES['theme_file'])) {
|
||||||
|
$res = save_uploaded_theme($_FILES['theme_file']);
|
||||||
|
if (!empty($res['ok'])) {
|
||||||
|
$notice = t('admin.settings.theme.notice_theme_imported');
|
||||||
|
} else {
|
||||||
|
$errors[] = $res['error'] ?? t('admin.settings.theme.error_theme_invalid');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.theme.error_theme_upload');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Standard typography & layout settings form submit
|
||||||
|
$fontChoice = $_POST['font_stack'] ?? 'sans';
|
||||||
|
$adminFontChoice = $_POST['admin_font_stack'] ?? 'sans';
|
||||||
|
$adminColorMode = $_POST['admin_color_mode'] ?? 'auto';
|
||||||
|
$colorMode = $_POST['color_mode'] ?? 'light';
|
||||||
|
$postListLayout = $_POST['post_list_layout'] ?? 'excerpt';
|
||||||
|
|
||||||
|
if (!in_array($fontChoice, ['sans', 'serif', 'mono'], true)) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_font');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($adminFontChoice, ['sans', 'serif', 'mono'], true)) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_admin_font');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($adminColorMode, ['light', 'dark', 'auto'], true)) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_admin_color');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($colorMode, ['light', 'dark', 'auto'], true)) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_color_mode');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($postListLayout, ['excerpt', 'full', 'archive'], true)) {
|
||||||
|
$errors[] = t('admin.settings.theme.error_post_layout');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
$config['theme']['font_stack'] = $fontChoice;
|
||||||
|
$config['theme']['admin_font_stack'] = $adminFontChoice;
|
||||||
|
$config['theme']['admin_color_mode'] = $adminColorMode;
|
||||||
|
$config['theme']['color_mode'] = $colorMode;
|
||||||
|
$config['theme']['post_list_layout'] = $postListLayout;
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
$notice = t('admin.settings.theme.notice_updated');
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.theme.error_save');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_theme_active(array $theme, array $activeThemeConfig): bool
|
||||||
|
{
|
||||||
|
if (!empty($activeThemeConfig['active_theme_name']) && $activeThemeConfig['active_theme_name'] === $theme['name']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasLight = !empty($theme['has_light']);
|
||||||
|
$hasDark = !empty($theme['has_dark']);
|
||||||
|
if (!$hasLight && !$hasDark) {
|
||||||
|
$hasLight = true;
|
||||||
|
$hasDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lightMatch = true;
|
||||||
|
if ($hasLight) {
|
||||||
|
$lightMatch = strcasecmp($theme['light']['bg'], $activeThemeConfig['background_color'] ?? '') === 0
|
||||||
|
&& strcasecmp($theme['light']['text'], $activeThemeConfig['text_color'] ?? '') === 0
|
||||||
|
&& strcasecmp($theme['light']['accent'], $activeThemeConfig['accent_color'] ?? '') === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$darkMatch = true;
|
||||||
|
if ($hasDark) {
|
||||||
|
$darkMatch = strcasecmp($theme['dark']['bg'], $activeThemeConfig['background_color_dark'] ?? '') === 0
|
||||||
|
&& strcasecmp($theme['dark']['text'], $activeThemeConfig['text_color_dark'] ?? '') === 0
|
||||||
|
&& strcasecmp($theme['dark']['accent'], $activeThemeConfig['accent_color_dark'] ?? '') === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lightMatch && $darkMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableThemes = get_available_themes();
|
||||||
|
|
||||||
|
$adminTitle = t('admin.settings.theme.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.settings.theme.heading')) ?></h1>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-notices.php'; ?>
|
||||||
|
|
||||||
|
<nav class="admin-actions">
|
||||||
|
<button class="save" type="submit" form="settings-form" aria-label="<?= e(t('admin.settings.nav.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.settings.nav.save')) ?>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<form method="post" id="settings-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.theme.section_fonts')) ?></span>
|
||||||
|
|
||||||
|
<label><b><?= e(t('admin.settings.theme.site_font')) ?></b></label>
|
||||||
|
<label class="inline-radio font-preview font-preview-sans" for="font_stack_sans">
|
||||||
|
<input type="radio" id="font_stack_sans" name="font_stack" value="sans" <?= ($config['theme']['font_stack'] ?? 'sans') === 'sans' ? 'checked' : '' ?>>
|
||||||
|
Sans (Inter)
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio font-preview font-preview-serif" for="font_stack_serif">
|
||||||
|
<input type="radio" id="font_stack_serif" name="font_stack" value="serif" <?= ($config['theme']['font_stack'] ?? 'sans') === 'serif' ? 'checked' : '' ?>>
|
||||||
|
Serif (Merriweather)
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio font-preview font-preview-mono" for="font_stack_mono">
|
||||||
|
<input type="radio" id="font_stack_mono" name="font_stack" value="mono" <?= ($config['theme']['font_stack'] ?? 'sans') === 'mono' ? 'checked' : '' ?>>
|
||||||
|
Mono (Iosevka)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label><b><?= e(t('admin.settings.theme.admin_font')) ?></b></label>
|
||||||
|
<label class="inline-radio font-preview font-preview-sans" for="admin_font_stack_sans">
|
||||||
|
<input type="radio" id="admin_font_stack_sans" name="admin_font_stack" value="sans" <?= ($config['theme']['admin_font_stack'] ?? 'sans') === 'sans' ? 'checked' : '' ?>>
|
||||||
|
Sans (Inter)
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio font-preview font-preview-serif" for="admin_font_stack_serif">
|
||||||
|
<input type="radio" id="admin_font_stack_serif" name="admin_font_stack" value="serif" <?= ($config['theme']['admin_font_stack'] ?? 'sans') === 'serif' ? 'checked' : '' ?>>
|
||||||
|
Serif (Merriweather)
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio font-preview font-preview-mono" for="admin_font_stack_mono">
|
||||||
|
<input type="radio" id="admin_font_stack_mono" name="admin_font_stack" value="mono" <?= ($config['theme']['admin_font_stack'] ?? 'sans') === 'mono' ? 'checked' : '' ?>>
|
||||||
|
Mono (Iosevka)
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.theme.section_color_mode')) ?></span>
|
||||||
|
|
||||||
|
<label><b><?= e(t('admin.settings.theme.site_color_mode')) ?></b></label>
|
||||||
|
<label class="inline-radio" for="color_mode_light">
|
||||||
|
<input type="radio" id="color_mode_light" name="color_mode" value="light" <?= ($config['theme']['color_mode'] ?? 'light') === 'light' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_light')) ?>
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio" for="color_mode_dark">
|
||||||
|
<input type="radio" id="color_mode_dark" name="color_mode" value="dark" <?= ($config['theme']['color_mode'] ?? 'light') === 'dark' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_dark')) ?>
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio" for="color_mode_auto">
|
||||||
|
<input type="radio" id="color_mode_auto" name="color_mode" value="auto" <?= ($config['theme']['color_mode'] ?? 'light') === 'auto' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_auto')) ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label><b><?= e(t('admin.settings.theme.admin_color_mode')) ?></b></label>
|
||||||
|
<label class="inline-radio" for="admin_color_mode_light">
|
||||||
|
<input type="radio" id="admin_color_mode_light" name="admin_color_mode" value="light" <?= ($config['theme']['admin_color_mode'] ?? 'auto') === 'light' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_light')) ?>
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio" for="admin_color_mode_dark">
|
||||||
|
<input type="radio" id="admin_color_mode_dark" name="admin_color_mode" value="dark" <?= ($config['theme']['admin_color_mode'] ?? 'auto') === 'dark' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_dark')) ?>
|
||||||
|
</label>
|
||||||
|
<label class="inline-radio" for="admin_color_mode_auto">
|
||||||
|
<input type="radio" id="admin_color_mode_auto" name="admin_color_mode" value="auto" <?= ($config['theme']['admin_color_mode'] ?? 'auto') === 'auto' ? 'checked' : '' ?>>
|
||||||
|
<?= e(t('admin.settings.theme.color_auto')) ?>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.theme.section_post_layout')) ?></span>
|
||||||
|
|
||||||
|
<div class="layout-options">
|
||||||
|
<label class="layout-choice" for="post_list_excerpt">
|
||||||
|
<input type="radio" id="post_list_excerpt" name="post_list_layout" value="excerpt" <?= ($config['theme']['post_list_layout'] ?? 'excerpt') === 'excerpt' ? 'checked' : '' ?>>
|
||||||
|
<picture class="layout-preview">
|
||||||
|
<source srcset="<?= base_path() ?>/admin/images/layouts/layout-excerpt-dark.png" media="(prefers-color-scheme: dark)">
|
||||||
|
<img src="<?= base_path() ?>/admin/images/layouts/layout-excerpt-light.png" alt="<?= e(t('admin.settings.theme.layout_excerpt')) ?>" loading="lazy">
|
||||||
|
</picture>
|
||||||
|
<span><?= e(t('admin.settings.theme.layout_excerpt')) ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="layout-choice" for="post_list_full">
|
||||||
|
<input type="radio" id="post_list_full" name="post_list_layout" value="full" <?= ($config['theme']['post_list_layout'] ?? 'excerpt') === 'full' ? 'checked' : '' ?>>
|
||||||
|
<picture class="layout-preview">
|
||||||
|
<source srcset="<?= base_path() ?>/admin/images/layouts/layout-full-dark.png" media="(prefers-color-scheme: dark)">
|
||||||
|
<img src="<?= base_path() ?>/admin/images/layouts/layout-full-light.png" alt="<?= e(t('admin.settings.theme.layout_full')) ?>" loading="lazy">
|
||||||
|
</picture>
|
||||||
|
<span><?= e(t('admin.settings.theme.layout_full')) ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="layout-choice" for="post_list_archive">
|
||||||
|
<input type="radio" id="post_list_archive" name="post_list_layout" value="archive" <?= ($config['theme']['post_list_layout'] ?? 'excerpt') === 'archive' ? 'checked' : '' ?>>
|
||||||
|
<picture class="layout-preview">
|
||||||
|
<source srcset="<?= base_path() ?>/admin/images/layouts/layout-archive-dark.png" media="(prefers-color-scheme: dark)">
|
||||||
|
<img src="<?= base_path() ?>/admin/images/layouts/layout-archive-light.png" alt="<?= e(t('admin.settings.theme.layout_archive')) ?>" loading="lazy">
|
||||||
|
</picture>
|
||||||
|
<span><?= e(t('admin.settings.theme.layout_archive')) ?></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.theme.section_themes')) ?></span>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$docsLink = '<a target="_blank" rel="noopener noreferrer" href="https://docs.pureblog.org/themes/">' . e(t('admin.settings.theme.docs_link')) . '</a>';
|
||||||
|
?>
|
||||||
|
<p><?= str_replace('{link}', $docsLink, t('admin.settings.theme.themes_intro')) ?></p>
|
||||||
|
|
||||||
|
<form method="post" id="theme-action-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<div class="theme-grid">
|
||||||
|
<?php foreach ($availableThemes as $th): ?>
|
||||||
|
<?php $isActive = is_theme_active($th, $config['theme']); ?>
|
||||||
|
<div class="theme-card<?= $isActive ? ' active' : '' ?>">
|
||||||
|
<div class="theme-card-header">
|
||||||
|
<span class="theme-card-title"><?= e($th['name']) ?></span>
|
||||||
|
<?php if ($isActive): ?>
|
||||||
|
<span class="theme-badge active-badge"><?= e(t('admin.settings.theme.active')) ?></span>
|
||||||
|
<?php elseif ($th['is_custom']): ?>
|
||||||
|
<span class="theme-badge custom-badge"><?= e(t('admin.settings.theme.custom')) ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="theme-swatch-group">
|
||||||
|
<?php if (!empty($th['has_light']) || empty($th['has_dark'])): ?>
|
||||||
|
<div class="theme-swatch-row">
|
||||||
|
<span class="swatch-label"><?= e(t('admin.settings.theme.light_mode')) ?></span>
|
||||||
|
<div class="swatch-chips">
|
||||||
|
<span class="swatch-chip" title="Background: <?= e($th['light']['bg']) ?>" style="background: <?= e($th['light']['bg']) ?>; border: 1px solid <?= e($th['light']['border']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Text: <?= e($th['light']['text']) ?>" style="background: <?= e($th['light']['text']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Accent: <?= e($th['light']['accent']) ?>" style="background: <?= e($th['light']['accent']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Border: <?= e($th['light']['border']) ?>" style="background: <?= e($th['light']['border']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Accent BG: <?= e($th['light']['accent_bg']) ?>" style="background: <?= e($th['light']['accent_bg']) ?>;"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($th['has_dark']) || empty($th['has_light'])): ?>
|
||||||
|
<div class="theme-swatch-row">
|
||||||
|
<span class="swatch-label"><?= e(t('admin.settings.theme.dark_mode')) ?></span>
|
||||||
|
<div class="swatch-chips">
|
||||||
|
<span class="swatch-chip" title="Background: <?= e($th['dark']['bg']) ?>" style="background: <?= e($th['dark']['bg']) ?>; border: 1px solid <?= e($th['dark']['border']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Text: <?= e($th['dark']['text']) ?>" style="background: <?= e($th['dark']['text']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Accent: <?= e($th['dark']['accent']) ?>" style="background: <?= e($th['dark']['accent']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Border: <?= e($th['dark']['border']) ?>" style="background: <?= e($th['dark']['border']) ?>;"></span>
|
||||||
|
<span class="swatch-chip" title="Accent BG: <?= e($th['dark']['accent_bg']) ?>" style="background: <?= e($th['dark']['accent_bg']) ?>;"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="theme-card-actions">
|
||||||
|
<?php if (!$isActive): ?>
|
||||||
|
<button type="submit" name="apply_theme_id" value="<?= e($th['id']) ?>" class="link-button apply">
|
||||||
|
<?= e(t('admin.settings.theme.apply')) ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
<a href="<?= e(base_path()) ?>/?theme_preview=<?= urlencode($th['id']) ?>" class="link-button preview" target="_blank" rel="noopener noreferrer">
|
||||||
|
<?= e(t('admin.settings.theme.preview')) ?>
|
||||||
|
</a>
|
||||||
|
<?php if ($th['is_custom']): ?>
|
||||||
|
<button type="submit" name="delete_theme_filename" value="<?= e($th['filename']) ?>" class="link-button delete" onclick="return confirm(<?= e(json_encode(t('admin.settings.theme.delete_confirm'))) ?>);">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.editor.delete')) ?>
|
||||||
|
</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<details class="theme-creator-details">
|
||||||
|
<summary class="theme-creator-summary"><b><?= e(t('admin.settings.theme.creator_title')) ?></b></summary>
|
||||||
|
<div class="theme-creator-body">
|
||||||
|
<p class="tip"><?= e(t('admin.settings.theme.creator_tip')) ?></p>
|
||||||
|
<form method="post" class="theme-creator-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="action" value="create_theme">
|
||||||
|
|
||||||
|
<label for="new_theme_name"><b><?= e(t('admin.settings.theme.theme_name')) ?></b></label>
|
||||||
|
<input type="text" id="new_theme_name" name="new_theme_name" placeholder="e.g. Sunset" required>
|
||||||
|
|
||||||
|
<h3><?= e(t('admin.settings.theme.light_mode')) ?></h3>
|
||||||
|
<div class="color-grid">
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_bg"><?= e(t('admin.settings.theme.color_background')) ?></label>
|
||||||
|
<input type="text" id="new_bg" name="new_bg" class="color-input" placeholder="#FAFAFA">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_text"><?= e(t('admin.settings.theme.color_text')) ?></label>
|
||||||
|
<input type="text" id="new_text" name="new_text" class="color-input" placeholder="#212121">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_accent"><?= e(t('admin.settings.theme.color_accent')) ?></label>
|
||||||
|
<input type="text" id="new_accent" name="new_accent" class="color-input" placeholder="#0D47A1">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_border"><?= e(t('admin.settings.theme.color_border')) ?></label>
|
||||||
|
<input type="text" id="new_border" name="new_border" class="color-input" placeholder="#898EA4">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_accent_bg"><?= e(t('admin.settings.theme.color_accent_bg')) ?></label>
|
||||||
|
<input type="text" id="new_accent_bg" name="new_accent_bg" class="color-input" placeholder="#F5F7FF">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3><?= e(t('admin.settings.theme.dark_mode')) ?></h3>
|
||||||
|
<div class="color-grid">
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_bg_dark"><?= e(t('admin.settings.theme.color_background')) ?></label>
|
||||||
|
<input type="text" id="new_bg_dark" name="new_bg_dark" class="color-input" placeholder="#212121">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_text_dark"><?= e(t('admin.settings.theme.color_text')) ?></label>
|
||||||
|
<input type="text" id="new_text_dark" name="new_text_dark" class="color-input" placeholder="#DCDCDC">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_accent_dark"><?= e(t('admin.settings.theme.color_accent')) ?></label>
|
||||||
|
<input type="text" id="new_accent_dark" name="new_accent_dark" class="color-input" placeholder="#FFB300">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_border_dark"><?= e(t('admin.settings.theme.color_border')) ?></label>
|
||||||
|
<input type="text" id="new_border_dark" name="new_border_dark" class="color-input" placeholder="#555555">
|
||||||
|
</div>
|
||||||
|
<div class="color-field">
|
||||||
|
<label for="new_accent_bg_dark"><?= e(t('admin.settings.theme.color_accent_bg')) ?></label>
|
||||||
|
<input type="text" id="new_accent_bg_dark" name="new_accent_bg_dark" class="color-input" placeholder="#2B2B2B">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 1rem;">
|
||||||
|
<button type="submit" class="save">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.settings.theme.save_theme')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll('.color-input').forEach(function(input) {
|
||||||
|
function updateColor() {
|
||||||
|
var val = input.value.trim();
|
||||||
|
if (val !== '' && !val.startsWith('#')) {
|
||||||
|
val = '#' + val;
|
||||||
|
}
|
||||||
|
var hex = val.replace(/^#/, '');
|
||||||
|
if (/^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) {
|
||||||
|
if (hex.length === 3) {
|
||||||
|
hex = hex.split('').map(function(c) { return c + c; }).join('');
|
||||||
|
}
|
||||||
|
var r = parseInt(hex.substring(0, 2), 16);
|
||||||
|
var g = parseInt(hex.substring(2, 4), 16);
|
||||||
|
var b = parseInt(hex.substring(4, 6), 16);
|
||||||
|
var yiq = (r * 299 + g * 587 + b * 114) / 1000;
|
||||||
|
input.style.backgroundColor = '#' + hex;
|
||||||
|
input.style.color = yiq >= 128 ? '#000000' : '#ffffff';
|
||||||
|
} else {
|
||||||
|
input.style.backgroundColor = '';
|
||||||
|
input.style.color = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input.addEventListener('input', updateColor);
|
||||||
|
input.addEventListener('change', updateColor);
|
||||||
|
if (input.value) updateColor();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.theme.section_import')) ?></span>
|
||||||
|
<form method="post" enctype="multipart/form-data" class="theme-import-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="action" value="import_theme">
|
||||||
|
<label for="theme_file"><?= e(t('admin.settings.theme.import_file_label')) ?> <span class="tip">(<?= e(t('admin.settings.theme.import_file_tip')) ?>)</span></label>
|
||||||
|
<div style="display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem;">
|
||||||
|
<input type="file" id="theme_file" name="theme_file" accept=".json,application/json" required style="margin-bottom: 0;">
|
||||||
|
<button type="submit" class="save" style="margin: 0; white-space: nowrap;">
|
||||||
|
<?= e(t('admin.settings.theme.import_button')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
264
admin/settings-updates.php
Normal file
|
|
@ -0,0 +1,264 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../includes/updater.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$latest = null;
|
||||||
|
if (isset($_GET['check']) || isset($_GET['package_plan'])) {
|
||||||
|
$latest = fetch_latest_pureblog_release();
|
||||||
|
}
|
||||||
|
$currentVersionDisplay = detect_current_pureblog_version();
|
||||||
|
$packagePlan = null;
|
||||||
|
$packagePlanError = '';
|
||||||
|
if (isset($_GET['package_plan'])) {
|
||||||
|
if ($latest === null || !($latest['ok'] ?? false)) {
|
||||||
|
$packagePlanError = (string) (($latest['error'] ?? '') !== '' ? $latest['error'] : t('admin.settings.updates.error_release_metadata'));
|
||||||
|
} else {
|
||||||
|
$latestTag = (string) ($latest['tag'] ?? '');
|
||||||
|
$currentVersion = detect_current_pureblog_version();
|
||||||
|
|
||||||
|
if ($latestTag !== '' && version_compare(ltrim($currentVersion, 'vV'), ltrim($latestTag, 'vV'), '>=')) {
|
||||||
|
$packagePlan = [
|
||||||
|
'ok' => true,
|
||||||
|
'already_latest' => true,
|
||||||
|
'message' => t('admin.settings.updates.already_latest_version', ['tag' => $latestTag]),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$packagePlan = build_package_upgrade_plan((string) ($latest['zipball_url'] ?? ''));
|
||||||
|
if (!($packagePlan['ok'] ?? false)) {
|
||||||
|
$packagePlanError = (string) ($packagePlan['error'] ?? t('admin.settings.updates.error_build_plan'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$applyResult = null;
|
||||||
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
verify_csrf();
|
||||||
|
if (isset($_POST['apply_update'])) {
|
||||||
|
$latestForApply = fetch_latest_pureblog_release();
|
||||||
|
if (!($latestForApply['ok'] ?? false)) {
|
||||||
|
$applyResult = [
|
||||||
|
'ok' => false,
|
||||||
|
'error' => (string) ($latestForApply['error'] ?? t('admin.settings.updates.error_release_metadata')),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$applyResult = apply_release_update(
|
||||||
|
(string) ($latestForApply['zipball_url'] ?? ''),
|
||||||
|
(string) ($latestForApply['tag'] ?? '')
|
||||||
|
);
|
||||||
|
if (($applyResult['ok'] ?? false) && !empty($latestForApply['tag'])) {
|
||||||
|
$currentVersionDisplay = normalize_version_label((string) $latestForApply['tag']);
|
||||||
|
// Redirect after a successful update so the result page loads
|
||||||
|
// with the newly written files rather than the in-memory copies
|
||||||
|
// from before the update ran.
|
||||||
|
$_SESSION['admin_action_flash'] = ['ok' => true, 'message' => t('admin.settings.updates.notice_update_applied')];
|
||||||
|
header('Location: ' . base_path() . '/admin/settings-updates.php?updated=1');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (isset($_POST['restore_backup'])) {
|
||||||
|
$backupName = trim((string) ($_POST['backup_name'] ?? ''));
|
||||||
|
$applyResult = restore_named_backup($backupName);
|
||||||
|
if ($applyResult['ok'] ?? false) {
|
||||||
|
$_SESSION['admin_action_flash'] = ['ok' => true, 'message' => t('admin.settings.updates.notice_backup_restored')];
|
||||||
|
header('Location: ' . base_path() . '/admin/settings-updates.php?restored=1');
|
||||||
|
exit;
|
||||||
|
} elseif ($backupName === '') {
|
||||||
|
$applyResult = ['ok' => false, 'error' => t('admin.settings.updates.error_choose_restore')];
|
||||||
|
}
|
||||||
|
} elseif (isset($_POST['delete_backup'])) {
|
||||||
|
$backupName = trim((string) ($_POST['backup_name'] ?? ''));
|
||||||
|
$applyResult = delete_named_backup($backupName);
|
||||||
|
if (!($applyResult['ok'] ?? false) && $backupName === '') {
|
||||||
|
$applyResult = ['ok' => false, 'error' => t('admin.settings.updates.error_choose_delete')];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableBackups = list_available_backups();
|
||||||
|
$latestBackup = $availableBackups[0] ?? '';
|
||||||
|
$latestBackupTimestamp = $latestBackup !== '' ? format_backup_timestamp($latestBackup) : '';
|
||||||
|
|
||||||
|
if (isset($_GET['package_plan']) && $packagePlan === null && $packagePlanError === '') {
|
||||||
|
$packagePlanError = t('admin.settings.updates.error_inspect');
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t('admin.settings.updates.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.settings.updates.heading')) ?></h1>
|
||||||
|
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.updates.section_version')) ?></span>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.current_version')) ?></strong> <?= e($currentVersionDisplay) ?></p>
|
||||||
|
<?php if ($latestBackup !== ''): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.last_backup')) ?></strong>
|
||||||
|
<?php if ($latestBackupTimestamp !== ''): ?>
|
||||||
|
<?= e($latestBackupTimestamp) ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<?= e(t('admin.settings.updates.unknown_time')) ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
(<code><?= e($latestBackup) ?></code>)
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.repository')) ?></strong> <a href="https://github.com/kevquirk/pureblog" target="_blank" rel="noopener noreferrer">github.com/kevquirk/pureblog</a></p>
|
||||||
|
<p>
|
||||||
|
<a class="button" href="<?= base_path() ?>/admin/settings-updates.php?check=1">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-upgrade"></use></svg>
|
||||||
|
<?= e(t('admin.settings.updates.check_release')) ?>
|
||||||
|
</a>
|
||||||
|
<a class="button" href="<?= base_path() ?>/admin/settings-updates.php?package_plan=1">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-eye"></use></svg>
|
||||||
|
<?= e(t('admin.settings.updates.inspect_package')) ?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?php if ($latest !== null && !($latest['ok'] ?? false)): ?>
|
||||||
|
<p class="notice delete"><?= e($latest['error'] ?? t('admin.settings.updates.error_check')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($latest !== null && ($latest['ok'] ?? false)): ?>
|
||||||
|
<?php
|
||||||
|
$latestTag = (string) ($latest['tag'] ?? '');
|
||||||
|
$currentVersion = detect_current_pureblog_version();
|
||||||
|
$updateAvailable = ($latestTag !== '' && $currentVersion !== 'unknown' && !versions_match($currentVersion, $latestTag));
|
||||||
|
$displayLatestVersion = ltrim($latestTag, 'v');
|
||||||
|
?>
|
||||||
|
<?php if ($updateAvailable): ?>
|
||||||
|
<h3 class="no-top-margin">🎉 New Version Available (v<?= e($displayLatestVersion) ?>)</h3>
|
||||||
|
<?php endif; ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.latest_release')) ?></strong> <?= e($latest['tag'] !== '' ? $latest['tag'] : ($latest['name'] ?? 'Unknown')) ?></p>
|
||||||
|
<?php if (($latest['published_at'] ?? '') !== ''): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.published')) ?></strong> <?= e(format_datetime_for_display((string) $latest['published_at'], $config, 'Y-m-d')) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<p><a href="<?= e($latest['url'] ?? 'https://github.com/kevquirk/pureblog/releases') ?>" target="_blank" rel="noopener noreferrer"><?= e(t('admin.settings.updates.view_release_notes')) ?></a></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<?php if ($packagePlanError !== ''): ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.updates.section_inspect')) ?></span>
|
||||||
|
<p class="notice delete"><?= e($packagePlanError) ?></p>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($packagePlan !== null && ($packagePlan['ok'] ?? false)): ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.updates.section_inspect')) ?></span>
|
||||||
|
<?php if (!empty($packagePlan['already_latest'])): ?>
|
||||||
|
<p><?= e((string) ($packagePlan['message'] ?? t('admin.settings.updates.already_latest'))) ?></p>
|
||||||
|
<?php elseif (!empty($packagePlan['breaking'])): ?>
|
||||||
|
<p class="notice delete"><strong>Manual upgrade required</strong> — this release contains breaking changes that cannot be applied automatically.</p>
|
||||||
|
<?php if (($packagePlan['breaking_instructions'] ?? '') !== ''): ?>
|
||||||
|
<p><?= e((string) $packagePlan['breaking_instructions']) ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<p><a class="button" href="https://github.com/kevquirk/pureblog/releases" target="_blank" rel="noopener noreferrer">Download from GitHub</a></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.planned_actions')) ?></strong></p>
|
||||||
|
<ul>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_add')) ?></strong> <?= e((string) ($packagePlan['counts']['add'] ?? 0)) ?></li>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_replace')) ?></strong> <?= e((string) ($packagePlan['counts']['replace'] ?? 0)) ?></li>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_unchanged')) ?></strong> <?= e((string) ($packagePlan['counts']['unchanged'] ?? 0)) ?></li>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_preserved')) ?></strong> <?= e((string) ($packagePlan['counts']['skip'] ?? 0)) ?></li>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_local_only')) ?></strong> <?= e((string) ($packagePlan['counts']['local_only'] ?? 0)) ?></li>
|
||||||
|
<?php if (($packagePlan['counts']['ignore'] ?? 0) > 0): ?>
|
||||||
|
<li><strong><?= e(t('admin.settings.updates.action_ignore')) ?></strong> <?= e((string) ($packagePlan['counts']['ignore'] ?? 0)) ?></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?php if (!empty($packagePlan['will_add'])): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.will_add')) ?></strong></p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($packagePlan['will_add'] as $path): ?>
|
||||||
|
<li><code><?= e($path) ?></code></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($packagePlan['will_replace'])): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.will_replace')) ?></strong></p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($packagePlan['will_replace'] as $path): ?>
|
||||||
|
<li><code><?= e($path) ?></code></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($packagePlan['will_ignore'])): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.will_ignore')) ?></strong></p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($packagePlan['will_ignore'] as $path): ?>
|
||||||
|
<li><code><?= e($path) ?></code></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($packagePlan['local_only'])): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.will_delete')) ?></strong></p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($packagePlan['local_only'] as $path): ?>
|
||||||
|
<li><code><?= e($path) ?></code></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/settings-updates.php" onsubmit="return confirm('<?= e(t('admin.settings.updates.apply_confirm')) ?>');">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<button class="button save" type="submit" name="apply_update" value="1">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-upgrade"></use></svg>
|
||||||
|
<?= e(t('admin.settings.updates.apply_update')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($availableBackups)): ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.updates.section_backup')) ?></span>
|
||||||
|
<p><?= e(t('admin.settings.updates.backup_info')) ?></p>
|
||||||
|
<form method="post" action="<?= base_path() ?>/admin/settings-updates.php">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<label for="backup-name"><?= e(t('admin.settings.updates.available_backups')) ?></label>
|
||||||
|
<select id="backup-name" name="backup_name" required>
|
||||||
|
<?php foreach ($availableBackups as $backupName): ?>
|
||||||
|
<option value="<?= e($backupName) ?>"><?= e($backupName) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<button class="button" type="submit" name="restore_backup" value="1" onclick="return confirm('<?= e(t('admin.settings.updates.restore_confirm')) ?>');">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-upgrade"></use></svg>
|
||||||
|
<?= e(t('admin.settings.updates.restore_backup')) ?>
|
||||||
|
</button>
|
||||||
|
<button class="button delete" type="submit" name="delete_backup" value="1" onclick="return confirm('<?= e(t('admin.settings.updates.delete_backup_confirm')) ?>');">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg>
|
||||||
|
<?= e(t('admin.settings.updates.delete_backup')) ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($applyResult !== null): ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.updates.section_result')) ?></span>
|
||||||
|
<?php if (!($applyResult['ok'] ?? false)): ?>
|
||||||
|
<p class="notice delete"><?= e((string) ($applyResult['error'] ?? t('admin.settings.updates.update_failed'))) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<p><?= e((string) ($applyResult['message'] ?? t('admin.settings.updates.update_completed'))) ?></p>
|
||||||
|
<?php if (!empty($applyResult['backup_path'])): ?>
|
||||||
|
<p><strong><?= e(t('admin.settings.updates.backup_path')) ?></strong> <code><?= e((string) $applyResult['backup_path']) ?></code></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
257
admin/settings-user.php
Normal file
|
|
@ -0,0 +1,257 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$config = load_config();
|
||||||
|
$fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans');
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$notice = '';
|
||||||
|
$newBackupCodes = $_SESSION['new_backup_codes'] ?? null;
|
||||||
|
unset($_SESSION['new_backup_codes']);
|
||||||
|
|
||||||
|
$mfaEnabled = !empty($config['mfa_enabled']) && !empty($config['mfa_secret']);
|
||||||
|
$isSettingUpMfa = !empty($_SESSION['mfa_setup_secret']) && !$mfaEnabled;
|
||||||
|
|
||||||
|
// Handle cancelling MFA setup
|
||||||
|
if (isset($_GET['cancel_mfa_setup'])) {
|
||||||
|
unset($_SESSION['mfa_setup_secret']);
|
||||||
|
header('Location: ' . base_path() . '/admin/settings-user.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start MFA setup (only generate a new secret if one does not already exist in session)
|
||||||
|
if (isset($_GET['setup_mfa']) && !$mfaEnabled) {
|
||||||
|
if (empty($_SESSION['mfa_setup_secret'])) {
|
||||||
|
$_SESSION['mfa_setup_secret'] = totp_generate_secret(16);
|
||||||
|
}
|
||||||
|
$isSettingUpMfa = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['admin_action_id'])) {
|
||||||
|
verify_csrf();
|
||||||
|
$mfaAction = $_POST['mfa_action'] ?? '';
|
||||||
|
|
||||||
|
if ($mfaAction === 'confirm_setup' && !empty($_SESSION['mfa_setup_secret'])) {
|
||||||
|
$secret = (string) $_SESSION['mfa_setup_secret'];
|
||||||
|
$code = trim((string) ($_POST['mfa_code'] ?? ''));
|
||||||
|
|
||||||
|
if (totp_verify_code($secret, $code)) {
|
||||||
|
$plainCodes = totp_generate_backup_codes(8);
|
||||||
|
$config['mfa_enabled'] = true;
|
||||||
|
$config['mfa_secret'] = $secret;
|
||||||
|
$config['mfa_backup_codes'] = totp_hash_backup_codes($plainCodes);
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
unset($_SESSION['mfa_setup_secret']);
|
||||||
|
$_SESSION['new_backup_codes'] = $plainCodes;
|
||||||
|
clear_all_remember_me_tokens();
|
||||||
|
$notice = t('admin.settings.user.mfa_notice_enabled');
|
||||||
|
$mfaEnabled = true;
|
||||||
|
$isSettingUpMfa = false;
|
||||||
|
$newBackupCodes = $plainCodes;
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.error_save');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.mfa_error_verify_code');
|
||||||
|
$isSettingUpMfa = true;
|
||||||
|
}
|
||||||
|
} elseif ($mfaAction === 'disable_mfa' && $mfaEnabled) {
|
||||||
|
$password = (string) ($_POST['mfa_disable_password'] ?? '');
|
||||||
|
if (password_verify($password, $config['admin_password_hash'] ?? '')) {
|
||||||
|
$config['mfa_enabled'] = false;
|
||||||
|
$config['mfa_secret'] = '';
|
||||||
|
$config['mfa_backup_codes'] = [];
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
clear_all_remember_me_tokens();
|
||||||
|
$notice = t('admin.settings.user.mfa_notice_disabled');
|
||||||
|
$mfaEnabled = false;
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.error_save');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.mfa_error_password');
|
||||||
|
}
|
||||||
|
} elseif ($mfaAction === 'regenerate_backup_codes' && $mfaEnabled) {
|
||||||
|
$password = (string) ($_POST['mfa_regenerate_password'] ?? '');
|
||||||
|
if (password_verify($password, $config['admin_password_hash'] ?? '')) {
|
||||||
|
$plainCodes = totp_generate_backup_codes(8);
|
||||||
|
$config['mfa_backup_codes'] = totp_hash_backup_codes($plainCodes);
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
$_SESSION['new_backup_codes'] = $plainCodes;
|
||||||
|
$notice = t('admin.settings.user.mfa_notice_codes_regenerated');
|
||||||
|
$newBackupCodes = $plainCodes;
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.error_save');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.mfa_error_password');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Main user profile update (username / password)
|
||||||
|
$adminUsername = trim($_POST['admin_username'] ?? '');
|
||||||
|
$passwordCurrent = $_POST['current_password'] ?? '';
|
||||||
|
$passwordNew = $_POST['new_password'] ?? '';
|
||||||
|
$passwordConfirm = $_POST['confirm_password'] ?? '';
|
||||||
|
|
||||||
|
if ($adminUsername === '') {
|
||||||
|
$errors[] = t('admin.settings.user.error_username');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($passwordNew !== '' || $passwordConfirm !== '') && $passwordNew !== $passwordConfirm) {
|
||||||
|
$errors[] = t('admin.settings.user.error_password_match');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($passwordNew !== '' && !password_verify($passwordCurrent, $config['admin_password_hash'] ?? '')) {
|
||||||
|
$errors[] = t('admin.settings.user.error_password_wrong');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
$config['admin_username'] = $adminUsername;
|
||||||
|
|
||||||
|
if ($passwordNew !== '') {
|
||||||
|
$config['admin_password_hash'] = password_hash($passwordNew, PASSWORD_DEFAULT);
|
||||||
|
clear_all_remember_me_tokens();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (save_config($config)) {
|
||||||
|
$notice = t('admin.settings.user.notice_updated');
|
||||||
|
} else {
|
||||||
|
$errors[] = t('admin.settings.user.error_save');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate QR code if setting up MFA
|
||||||
|
$mfaQrSvg = '';
|
||||||
|
$mfaProvisioningUri = '';
|
||||||
|
$mfaSecret = '';
|
||||||
|
if ($isSettingUpMfa && !empty($_SESSION['mfa_setup_secret'])) {
|
||||||
|
$mfaSecret = (string) $_SESSION['mfa_setup_secret'];
|
||||||
|
$siteTitle = $config['site_title'] ?? 'Pure Blog';
|
||||||
|
$accountName = $config['admin_username'] ?? 'admin';
|
||||||
|
$mfaProvisioningUri = totp_get_provisioning_uri($mfaSecret, $accountName, $siteTitle);
|
||||||
|
$mfaQrSvg = qrcode_svg($mfaProvisioningUri, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$adminTitle = t('admin.settings.user.page_title');
|
||||||
|
require __DIR__ . '/../includes/admin-head.php';
|
||||||
|
?>
|
||||||
|
<main class="mid">
|
||||||
|
<h1><?= e(t('admin.settings.user.heading')) ?></h1>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-notices.php'; ?>
|
||||||
|
|
||||||
|
<nav class="admin-actions">
|
||||||
|
<button class="save" type="submit" form="settings-form" aria-label="<?= e(t('admin.settings.nav.save')) ?>">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg>
|
||||||
|
<?= e(t('admin.settings.nav.save')) ?>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<form method="post" id="settings-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.user.section_account')) ?></span>
|
||||||
|
<label for="admin_username"><?= e(t('admin.settings.user.username')) ?></label>
|
||||||
|
<input type="text" id="admin_username" name="admin_username" value="<?= e($config['admin_username'] ?? '') ?>" required>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.user.section_password')) ?></span>
|
||||||
|
<label for="current_password"><?= e(t('admin.settings.user.current_password')) ?></label>
|
||||||
|
<input type="password" id="current_password" name="current_password">
|
||||||
|
|
||||||
|
<label for="new_password"><?= e(t('admin.settings.user.new_password')) ?></label>
|
||||||
|
<input type="password" id="new_password" name="new_password">
|
||||||
|
|
||||||
|
<label for="confirm_password"><?= e(t('admin.settings.user.confirm_password')) ?></label>
|
||||||
|
<input type="password" id="confirm_password" name="confirm_password">
|
||||||
|
</section>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<section class="section-divider">
|
||||||
|
<span class="title"><?= e(t('admin.settings.user.mfa_section_title')) ?></span>
|
||||||
|
|
||||||
|
<?php if (!empty($newBackupCodes)): ?>
|
||||||
|
<div class="notice" style="margin-bottom: 1.5rem;">
|
||||||
|
<strong><?= e(t('admin.settings.user.mfa_backup_codes_heading')) ?></strong>
|
||||||
|
<p><?= e(t('admin.settings.user.mfa_backup_codes_warning')) ?></p>
|
||||||
|
<pre style="background: var(--bg-color); padding: 1rem; font-size: 1.1rem; line-height: 1.8; user-select: all; border: 1px dashed var(--border-color); margin: 0.75rem 0;"><code><?= e(implode("\n", $newBackupCodes)) ?></code></pre>
|
||||||
|
<button type="button" class="link-button" onclick="navigator.clipboard.writeText(<?= e(json_encode(implode("\n", $newBackupCodes))) ?>).then(()=>{this.innerHTML='<svg class=\'icon\' aria-hidden=\'true\'><use href=\'#icon-circle-check\'></use></svg> <?= e(addslashes(t('admin.settings.user.mfa_copied'))) ?>'; setTimeout(()=>{this.innerHTML='<svg class=\'icon\' aria-hidden=\'true\'><use href=\'#icon-copy\'></use></svg> <?= e(addslashes(t('admin.settings.user.mfa_copy_codes'))) ?>';}, 2500);})">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-copy"></use></svg> <?= e(t('admin.settings.user.mfa_copy_codes')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($mfaEnabled): ?>
|
||||||
|
<p>
|
||||||
|
<span style="display: inline-flex; align-items: center; gap: 0.35rem; color: #2e7d32; font-weight: bold;">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-circle-check"></use></svg>
|
||||||
|
<?= e(t('admin.settings.user.mfa_status_enabled')) ?>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p><?= e(t('admin.settings.user.mfa_enabled_desc')) ?></p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<details style="margin-bottom: 1.25rem;">
|
||||||
|
<summary style="cursor: pointer; font-weight: bold;"><?= e(t('admin.settings.user.mfa_regenerate_codes_title')) ?></summary>
|
||||||
|
<form method="post" style="margin-top: 1rem;">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="mfa_action" value="regenerate_backup_codes">
|
||||||
|
<label for="mfa_regenerate_password"><?= e(t('admin.settings.user.mfa_confirm_password_label')) ?></label>
|
||||||
|
<input type="password" id="mfa_regenerate_password" name="mfa_regenerate_password" required>
|
||||||
|
<button type="submit"><svg class="icon" aria-hidden="true"><use href="#icon-save"></use></svg> <?= e(t('admin.settings.user.mfa_regenerate_codes_btn')) ?></button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary style="cursor: pointer; font-weight: bold; color: var(--delete-color, inherit);"><?= e(t('admin.settings.user.mfa_disable_title')) ?></summary>
|
||||||
|
<form method="post" style="margin-top: 1rem;">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="mfa_action" value="disable_mfa">
|
||||||
|
<label for="mfa_disable_password"><?= e(t('admin.settings.user.mfa_confirm_password_label')) ?></label>
|
||||||
|
<input type="password" id="mfa_disable_password" name="mfa_disable_password" required>
|
||||||
|
<button type="submit" class="delete"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.settings.user.mfa_disable_btn')) ?></button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
<?php elseif ($isSettingUpMfa): ?>
|
||||||
|
<p><?= e(t('admin.settings.user.mfa_setup_instructions')) ?></p>
|
||||||
|
|
||||||
|
<div style="display: flex; flex-wrap: wrap; gap: 2rem; align-items: flex-start; margin: 1.5rem 0;">
|
||||||
|
<div style="background: #ffffff; padding: 0.75rem; border: 1px solid var(--border-color); display: inline-block; border-radius: 4px;">
|
||||||
|
<?= $mfaQrSvg ?>
|
||||||
|
</div>
|
||||||
|
<div style="flex: 1; min-width: 250px;">
|
||||||
|
<p style="margin-top: 0;"><?= e(t('admin.settings.user.mfa_manual_entry_intro')) ?></p>
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0 1.25rem 0;">
|
||||||
|
<code style="font-size: 1.15rem; font-weight: bold; padding: 0.35rem 0.6rem; letter-spacing: 0.05em; user-select: all;"><?= e($mfaSecret) ?></code>
|
||||||
|
<button type="button" class="link-button" onclick="navigator.clipboard.writeText('<?= e($mfaSecret) ?>').then(()=>{this.innerHTML='<svg class=\'icon\' aria-hidden=\'true\'><use href=\'#icon-circle-check\'></use></svg> <?= e(addslashes(t('admin.settings.user.mfa_copied'))) ?>'; setTimeout(()=>{this.innerHTML='<svg class=\'icon\' aria-hidden=\'true\'><use href=\'#icon-copy\'></use></svg> <?= e(addslashes(t('admin.settings.user.mfa_copy'))) ?>';}, 2000);})">
|
||||||
|
<svg class="icon" aria-hidden="true"><use href="#icon-copy"></use></svg> <?= e(t('admin.settings.user.mfa_copy')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post" action="<?= e(base_path()) ?>/admin/settings-user.php">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="mfa_action" value="confirm_setup">
|
||||||
|
<label for="mfa_code"><?= e(t('admin.settings.user.mfa_enter_code_label')) ?></label>
|
||||||
|
<input type="text" id="mfa_code" name="mfa_code" autofocus inputmode="numeric" autocomplete="one-time-code" placeholder="123456" required>
|
||||||
|
<div style="display: flex; gap: 0.5rem; align-items: center; margin-top: 1rem;">
|
||||||
|
<button type="submit"><svg class="icon" aria-hidden="true"><use href="#icon-circle-check"></use></svg> <?= e(t('admin.settings.user.mfa_activate_btn')) ?></button>
|
||||||
|
<a href="?cancel_mfa_setup=1" class="button link-button"><svg class="icon" aria-hidden="true"><use href="#icon-circle-x"></use></svg> <?= e(t('admin.settings.user.mfa_cancel_btn')) ?></a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<p><?= e(t('admin.settings.user.mfa_disabled_desc')) ?></p>
|
||||||
|
<a href="?setup_mfa=1" class="button"><svg class="icon" aria-hidden="true"><use href="#icon-circle-check"></use></svg> <?= e(t('admin.settings.user.mfa_setup_btn')) ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|
||||||
8
admin/settings.php
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/../functions.php';
|
||||||
|
|
||||||
|
header('Location: ' . base_path() . '/admin/settings-site.php', true, 302);
|
||||||
|
exit;
|
||||||
169
admin/upload-image.php
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
// Detect when post_max_size is exceeded (PHP empties $_POST and $_FILES on POST requests)
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST) && empty($_FILES) && (int) ($_SERVER['CONTENT_LENGTH'] ?? 0) > 0) {
|
||||||
|
$postMaxSize = ini_get('post_max_size') ?: 'unknown';
|
||||||
|
$error = t('admin.editor.error_upload_post_size', ['limit' => $postMaxSize]);
|
||||||
|
$redirect = base_path() . '/admin/content.php?upload_error=' . urlencode($error);
|
||||||
|
header('Location: ' . $redirect);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_csrf();
|
||||||
|
|
||||||
|
$slug = trim($_POST['slug'] ?? '');
|
||||||
|
$date = trim($_POST['date'] ?? '');
|
||||||
|
$editorType = trim($_POST['editor_type'] ?? 'post');
|
||||||
|
$messages = [];
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($slug === '') {
|
||||||
|
$errors[] = t('admin.editor.error_upload_no_slug');
|
||||||
|
} elseif (!isset($_FILES['image'])) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_no_file');
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileList = [];
|
||||||
|
if (empty($errors) && isset($_FILES['image'])) {
|
||||||
|
if (is_array($_FILES['image']['name'])) {
|
||||||
|
$count = count($_FILES['image']['name']);
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
if ($_FILES['image']['error'][$i] === UPLOAD_ERR_NO_FILE && $count > 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$fileList[] = [
|
||||||
|
'name' => (string) $_FILES['image']['name'][$i],
|
||||||
|
'type' => (string) ($_FILES['image']['type'][$i] ?? ''),
|
||||||
|
'tmp_name' => (string) ($_FILES['image']['tmp_name'][$i] ?? ''),
|
||||||
|
'error' => (int) $_FILES['image']['error'][$i],
|
||||||
|
'size' => (int) $_FILES['image']['size'][$i],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$fileList[] = [
|
||||||
|
'name' => (string) $_FILES['image']['name'],
|
||||||
|
'type' => (string) ($_FILES['image']['type'] ?? ''),
|
||||||
|
'tmp_name' => (string) ($_FILES['image']['tmp_name'] ?? ''),
|
||||||
|
'error' => (int) $_FILES['image']['error'],
|
||||||
|
'size' => (int) $_FILES['image']['size'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($fileList)) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_no_file');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = $slug;
|
||||||
|
if (empty($errors)) {
|
||||||
|
if (!is_safe_image_slug($folder)) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_invalid_slug');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
$baseDir = realpath(__DIR__ . '/../content/images');
|
||||||
|
$uploadDir = __DIR__ . '/../content/images/' . $folder;
|
||||||
|
|
||||||
|
if ($baseDir !== false && !is_file($baseDir . '/.htaccess')) {
|
||||||
|
file_put_contents($baseDir . '/.htaccess', "<FilesMatch \"\.ph(p[0-9]?|tml)$\">\n Require all denied\n</FilesMatch>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($baseDir === false) {
|
||||||
|
$errors[] = t('admin.editor.error_image_folder_missing');
|
||||||
|
} elseif (!is_dir($uploadDir) && !mkdir($uploadDir, 0755, true)) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_folder_create');
|
||||||
|
} elseif (!validate_image_path($baseDir, $uploadDir)) {
|
||||||
|
@rmdir($uploadDir);
|
||||||
|
$errors[] = t('admin.editor.error_image_invalid_path');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
$allowedTypes = [
|
||||||
|
'image/jpeg' => 'jpg',
|
||||||
|
'image/png' => 'png',
|
||||||
|
'image/gif' => 'gif',
|
||||||
|
'image/webp' => 'webp',
|
||||||
|
'image/avif' => 'avif',
|
||||||
|
];
|
||||||
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||||
|
|
||||||
|
foreach ($fileList as $file) {
|
||||||
|
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||||
|
$uploadErr = $file['error'];
|
||||||
|
$maxFileSize = ini_get('upload_max_filesize') ?: 'unknown';
|
||||||
|
$errors[] = match ($uploadErr) {
|
||||||
|
UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => t('admin.editor.error_upload_size', ['limit' => $maxFileSize]),
|
||||||
|
UPLOAD_ERR_PARTIAL => t('admin.editor.error_upload_partial'),
|
||||||
|
UPLOAD_ERR_NO_FILE => t('admin.editor.error_upload_no_file'),
|
||||||
|
UPLOAD_ERR_NO_TMP_DIR => t('admin.editor.error_upload_no_tmp_dir'),
|
||||||
|
UPLOAD_ERR_CANT_WRITE => t('admin.editor.error_upload_cant_write'),
|
||||||
|
UPLOAD_ERR_EXTENSION => t('admin.editor.error_upload_extension'),
|
||||||
|
default => t('admin.editor.error_upload_failed'),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mimeType = $finfo->file($file['tmp_name']) ?: '';
|
||||||
|
if (!isset($allowedTypes[$mimeType])) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_type') . ' (' . htmlspecialchars($file['name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . ')';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedFilename = basename($file['name']);
|
||||||
|
$uploadedFilename = preg_replace('/[^a-zA-Z0-9._-]/', '-', $uploadedFilename) ?? $uploadedFilename;
|
||||||
|
$uploadedFilename = preg_replace('/-+/', '-', $uploadedFilename) ?? $uploadedFilename;
|
||||||
|
$uploadedFilename = trim($uploadedFilename, '-');
|
||||||
|
|
||||||
|
$expectedExt = $allowedTypes[$mimeType];
|
||||||
|
$baseName = pathinfo($uploadedFilename, PATHINFO_FILENAME);
|
||||||
|
$baseName = str_replace('.', '-', $baseName);
|
||||||
|
$filename = $baseName . '.' . $expectedExt;
|
||||||
|
|
||||||
|
if ($filename === '') {
|
||||||
|
$errors[] = t('admin.editor.error_upload_invalid_name');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_file($uploadDir . '/' . $filename)) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_duplicate', ['filename' => $filename]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$destination = $uploadDir . '/' . $filename;
|
||||||
|
if (!move_uploaded_file($file['tmp_name'], $destination)) {
|
||||||
|
$errors[] = t('admin.editor.error_upload_save') . ' (' . htmlspecialchars($filename, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . ')';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
strip_image_metadata($destination, $mimeType);
|
||||||
|
call_hook('on_image_uploaded', [$destination]);
|
||||||
|
$webpDestination = preg_replace('/\.[^.]+$/', '.webp', $destination) ?? $destination;
|
||||||
|
if ($webpDestination !== $destination && file_exists($webpDestination)) {
|
||||||
|
$destination = $webpDestination;
|
||||||
|
}
|
||||||
|
$filename = basename($destination);
|
||||||
|
generate_image_thumbnail($destination, $uploadDir . '/thumbs/' . $filename);
|
||||||
|
$url = base_path() . '/content/images/' . $folder . '/' . $filename;
|
||||||
|
$altText = pathinfo($filename, PATHINFO_FILENAME) ?: 'image';
|
||||||
|
$messages[] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$redirect = $editorType === 'page'
|
||||||
|
? base_path() . '/admin/edit-page.php?slug=' . urlencode($slug)
|
||||||
|
: base_path() . '/admin/edit-post.php?slug=' . urlencode($slug);
|
||||||
|
if (!empty($messages)) {
|
||||||
|
$redirect .= '&uploaded=' . urlencode(implode("\n", $messages));
|
||||||
|
}
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$redirect .= '&upload_error=' . urlencode(implode(' ', $errors));
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ' . $redirect);
|
||||||
|
exit;
|
||||||
1016
assets/css/style.css
Normal file
BIN
assets/fonts/inter/Inter-Bold.ttf
Normal file
BIN
assets/fonts/inter/bold-italic.woff2
Normal file
BIN
assets/fonts/inter/bold.woff2
Normal file
BIN
assets/fonts/inter/italic.woff2
Normal file
BIN
assets/fonts/inter/regular.woff2
Normal file
BIN
assets/fonts/iosevka/Iosevka-Bold.ttf
Normal file
BIN
assets/fonts/iosevka/subset-bold.woff
Normal file
BIN
assets/fonts/iosevka/subset-bold.woff2
Normal file
BIN
assets/fonts/iosevka/subset-bolditalic.woff
Normal file
BIN
assets/fonts/iosevka/subset-bolditalic.woff2
Normal file
BIN
assets/fonts/iosevka/subset-italic.woff
Normal file
BIN
assets/fonts/iosevka/subset-italic.woff2
Normal file
BIN
assets/fonts/iosevka/subset-regular.woff
Normal file
BIN
assets/fonts/iosevka/subset-regular.woff2
Normal file
BIN
assets/fonts/merriweather/Merriweather-Bold.ttf
Normal file
BIN
assets/fonts/merriweather/bold-italic.woff
Normal file
BIN
assets/fonts/merriweather/bold-italic.woff2
Normal file
BIN
assets/fonts/merriweather/bold.woff
Normal file
BIN
assets/fonts/merriweather/bold.woff2
Normal file
BIN
assets/fonts/merriweather/italic.woff
Normal file
BIN
assets/fonts/merriweather/italic.woff2
Normal file
BIN
assets/fonts/merriweather/regular.woff
Normal file
BIN
assets/fonts/merriweather/regular.woff2
Normal file
21
assets/icons/sprite.svg
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" style="display:none">
|
||||||
|
<symbol id="icon-calendar" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M8 2v4"/>
|
||||||
|
<path d="M16 2v4"/>
|
||||||
|
<rect width="18" height="18" x="3" y="4" rx="2"/>
|
||||||
|
<path d="M3 10h18"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="icon-edit" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z"/>
|
||||||
|
<path d="M14.487 7.858A1 1 0 0 1 14 7V2"/>
|
||||||
|
<path d="M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516"/>
|
||||||
|
<path d="M8 18h1"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="icon-clock" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/>
|
||||||
|
</symbol>
|
||||||
|
<symbol id="icon-tag" viewBox="0 0 40 32">
|
||||||
|
<path d="M38.5 0h-12c-0.825 0-1.977 0.477-2.561 1.061l-14.879 14.879c-0.583 0.583-0.583 1.538 0 2.121l12.879 12.879c0.583 0.583 1.538 0.583 2.121 0l14.879-14.879c0.583-0.583 1.061-1.736 1.061-2.561v-12c0-0.825-0.675-1.5-1.5-1.5zM31 12c-1.657 0-3-1.343-3-3s1.343-3 3-3 3 1.343 3 3-1.343 3-3 3z"></path>
|
||||||
|
<path d="M4 17l17-17h-2.5c-0.825 0-1.977 0.477-2.561 1.061l-14.879 14.879c-0.583 0.583-0.583 1.538 0 2.121l12.879 12.879c0.583 0.583 1.538 0.583 2.121 0l0.939-0.939-13-13z"></path>
|
||||||
|
</symbol>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
BIN
assets/images/favicon.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
assets/images/og-image.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
1
content/.version-cache
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
v3.9.2
|
||||||
1
content/autosaves/page-2026bingo.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791071231,"title":"2026 Bingo","content":"# (the rest of) 2026 Bingo\r\n\r\n<img src=\"https:\/\/64.media.tumblr.com\/b5747897a4f8ab26cf850227e0f54d0e\/d513426cd53c0af2-e4\/s1280x1920\/62cd06ca1175af6b87062fd584c82900b50829de.png\">\r\nI didn't make one of these at the beginning of the year because I hadn't heard of them, but a friend of mine shared her progress and I really really liked the idea.\r\n\r\nIf you can't read my horrendous handwriting, the goals are:\r\n\r\n- **Write at least 15,000 words on the same project.** I haven't started the project yet, whoops...\r\n\r\n- **Get my writing professionally published again** | Submissions count: 2\/?\r\n\r\n- **Finish all exchanges I've signed up for without defaulting**\r\n\r\n- **Volunteer at least once at meeting** | Potentially going to be volunteering Sept 21\r\n\r\n- **Eat more nutritiously for a month straight** \r\n\r\n- **Finish at least 20 books.** | Currently: 7\/20\r\n\r\n- **Begin writing my own web series**\r\n\r\n- **Make at least 1 more song I'm proud of** | Count: 0\/1+\r\n\r\n- **Finish fall semester with at least a 3.8 GPA**\r\n\r\n- **Get verified on VGEN** | On hold as I recover from illness.\r\n\r\n- **Save up at least $3,000 more.** | $2035\/3000\r\n\r\n- **Start learning another language** | Status: still deciding which. Most likely Japanese as I plan on taking it in the Summer 2027 semester, but potentially concurrently with another language I haven't decided on yet.\r\n\r\n- **FREE SPACE**\r\n\r\n- **Get put on the new member board at meeting** \r\n\r\n- **Learn enough Python to make a new web app**\r\n\r\n- **Continue to improve my art, both visual and digital**\r\n\r\n- **Make another twine game** | Status: Still brainstorming. May set it in the universe of my future web series.\r\n\r\n- **Cut back to 400mg caffeine per day** \r\n\r\n- **Make at least 1 IRL friend** | 0\/1\r\n\r\n- **Consistently write at least 200 words\/day**\r\n\r\n- **Journal at least 1 page every day for at least 1 month**\r\n\r\n- **Have less than 5 breakdowns per month, ideally zero** (lol)\r\n\r\n- **Donate most of my clothes\/downsize wardrobe**\r\n\r\n- **See Caleb Mir again** | The SFA s2 sneak peek is at NYCC 2026, Oct 10th. We'll see!\r\n\r\n- **DO IT SCARED!** | I'll know this is complete when the time comes. I'll just know.","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-about.json
Normal file
1
content/autosaves/page-adoptables.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791072877,"title":"Adoptables!","content":"# Adoptables!\r\n\r\nYou can take these lil pixel aliens and put them on your site with a link back if you like them! Please save and upload to your site or a file host instead of hotlinking, thank you!\r\n\r\nLast updated Aug 14 2026\r\n\r\n<h3>Aggles<\/h3>\r\n\r\n<p>These little guys are called Aggles haha get it? Like my name?<\/p>\r\n\r\n<p><img src=\"https:\/\/cupboard.alien.town\/u\/h1IG71.png\" alt=\"a teal pixel alien with multiple eyes protruding from the forehead and brown hair and pink wings\"><img src=\"https:\/\/cupboard.alien.town\/u\/f7EOww.png\" alt=\"a purple pixel alien with multiple eyes protruding from the forehead and half black half red pigtails and purple wings\"><img src=\"https:\/\/cupboard.alien.town\/u\/fhfcAc.png\" alt=\"a yellow pixel alien with multiple eyes protruding from the forehead and pink long hair and orange wings\">\r\n<img src=\"https:\/\/cupboard.alien.town\/u\/QKFPPK.png\" alt=\"a coral colored pixel alien with multiple eyes protruding from the forehead and red hair and red and white wings\"><\/p>","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-badges.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073185,"title":"Fandom Badges","content":"<p>From <a href=\"https:\/\/femslashfete.dreamwidth.org\/\" rel=\"nofollow\">femslashfete<\/a> on Dreamwidth:<br \/>\r\n<img src=\"https:\/\/64.media.tumblr.com\/40f357f299456844f903ad7bf27df56a\/02b47ce67b92eb7b-7b\/s250x400\/f458de0526738b3e3d8349aa495200fc1acbbff5.png\" alt=\"10 fills badge\"> <img src=\"https:\/\/64.media.tumblr.com\/569a8ad7e01cd3b34da0d414d1738b82\/66b96963745f1d85-52\/s250x400\/bc23c5f37007bb4555df93ca30be5d180c5a9a0b.pnj\" alt=\"1 character 5 different ships badge\"> <img src=\"https:\/\/64.media.tumblr.com\/514bce29bf71193be736199a78aa0cbd\/02b47ce67b92eb7b-e1\/s250x400\/42d980bdf1a358ea766a25c83f8afcd9126fbf47.png\" alt=\"25 fills badge\"><img src=\"https:\/\/64.media.tumblr.com\/b6282b30a14cb7c28f70c1dc05f7fe77\/ab1db018cf48c7bc-cd\/s250x400\/b783f61207e90c28393949344ab0258a151c5f6a.png\" alt=\"femslashfete badge: medium munch: 5 fills in 5 different mediums\"><\/p>\r\nFrom elasticella's Fresh Femslash Salad Bar on dreamwidth:<br \/>\r\n2026: <img src=\"https:\/\/64.media.tumblr.com\/43e57bf24650de909ae06dcb8d2944e7\/b06c9b132b15aa19-f2\/s250x400\/58dd49ac3f682fa27eafedcdc6ef51d0630dee55.jpg\" alt=\"one hard fill\"><img src=\"https:\/\/64.media.tumblr.com\/b9e39a1c10b48828eb7dde7ff2ab4c73\/b06c9b132b15aa19-27\/s250x400\/aea2952fe64d96a24cef3a4d2dbc014a9bc6c15a.jpg\" alt=\"four fills\"><br \/>\r\n2025: <img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/1hf.png\" alt=\"one hard fill\"> 2024: <img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/fhf.png\" alt=\"four hard fills\"><\/p>\r\n\r\nFrom elasticella's filthy femslash fantasies ficathon 2026:<br \/>\r\n<img src=\"https:\/\/64.media.tumblr.com\/0ab8e439b94b0625fa42cfec10adaae2\/9210cef457cf0ff0-ce\/s250x400\/20620e965fd106fdeac2c0cd60ae13508a533cbe.png\" alt=\"1 fill badge\">\r\nFrom July Break Bingo (2025) on Tumblr\/discord: (please do NOT steal or alter these, at the request of the creators)<br \/>\r\n<img src=\"https:\/\/64.media.tumblr.com\/4f5211065bc208f73c845a03b134f8d7\/bdeb83d8a6a33f09-60\/s400x600\/56c60b66f110bb08a95e29bb92006553276803f1.pnj\" alt=\"two discord emojis, a \" width=\"250px\">\r\n\r\nFrom elasticella's Hotties Haunting the Narrative event on dreamwidth:<br \/>\r\n<img src=\"https:\/\/64.media.tumblr.com\/3a678a37f1761efd6435dbb19e44e027\/ccc0fa30dd935a3e-12\/s250x400\/6d653e5025cb3cf39658528c71cce08728134392.png\" alt=\"3 fills\">\r\n\r\nFrom MY Rarest of Rarepairs event 2025 (this is the first year we have graphic awards and I think they're fun):<br \/>\r\n<img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/tumblr_a5d75cf065c5812ea75288e1283a098d_6cb972ab_250-removebg-preview.png\" alt=\"1 fill\"><\/p>\r\nFrom beagoldfish microbang:<br \/>\r\n<img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/toothpastepancake-5.jpg\" alt=\"be a goldfish fill completion badge showing completed recipes, gifsets, playlists and fanfiction\" width=\"380px\"><\/p>\r\n\r\nFrom <a href=\"https:\/\/robinboob.com\/\" rel=\"nofollow\">robinboob<\/a>:<br \/>\r\n<img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/shipbadge.png\" alt=\"negative spirit x larry trainor joke ship ownership certificate\" width=\"380px\"><br \/>\r\n<img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/solara%20certificate.png\" alt=\"alara x solana joke ship ownership certificate\" width=\"380px\"><br \/>\r\n<img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/certificates_555_watermarked-1772138825413.png\" alt=\"mr morden x anna sheridan joke ship ownership certificate\" width=\"380px\"><br \/>\r\n<img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/ship-certificate-watermarked(1).png\" alt=\"kosh x lyta joke ship ownership certificate\" width=\"380px\"><\/p>","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-buttons.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073033,"title":"Button Wall","content":"# Button Wall\r\n\r\n<p>friends, mutuals, cool internet people i like:<br \/>\r\n<br \/>\r\n<a href=\"https:\/\/serpentinemalign.neocities.org\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/smbutton.png\" alt=\"button for serpentinemalign\" title=\"button for serpentinemalign\"><\/a><a href=\"https:\/\/eunoia.sayitditto.net\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/eunoia.png\" alt=\"button for euonoia\" title=\"button for euonoia\"><\/a><a href=\"https:\/\/linkyblog.neocities.org\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/linkybanner.png\" alt=\"button for linky\" title=\"button for linky\"><\/a><a href=\"https:\/\/www.hellomei.dev\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/hellomei.gif\" alt=\"button for hellomei\" title=\"button for hellomei\"><\/a><a href=\"https:\/\/maevedarcy.neocities.org\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/maeve.png\" width=\"63px\" alt=\"button for maevedarcy\" title=\"button for maevedarcy\"><\/a><a href=\"https:\/\/overmore.neocities.org\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/aJzQmzrHVB4BLKwu\/ul9xd6.png\" title=\"button for overmore\" alt=\"button for overmore\"><\/a><a href=\"https:\/\/herewithin.neocities.org\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/link-banner.png\" alt=\"button for herewithin\" title=\"button for herewithin\"><\/a><a href=\"https:\/\/brennan.day\/\" rel=\"nofollow\"><img src=\"https:\/\/file.garden\/Zw17vw8ctXTQw7PV\/brennan-day.gif\" alt=\"site button for brennan dot day\"><\/a><\/p>","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-creativity.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073268,"title":"Creativity","content":"Links for my creative work go here :3\r\n\r\n[Art Gallery](https:\/\/gallery.agnes.love\/)\r\n\r\n....... [Old Art 2022-2025](https:\/\/agnes.femslash.city\/oldart\/)\r\n\r\n[Writing Portfolio](https:\/\/agnes.alien.town\/)\r\n\r\n[Itch.Io](https:\/\/agnesthealien.itch.io\/)\r\n\r\n[AO3](https:\/\/archiveofourown.org\/users\/toothp4ste)","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-junk.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073845,"title":"Yard Sale","content":"This stuff is for low pressure, very chill sale. Email me at agnes@omg.lol to discuss.\r\n\r\nPRICING: Flexible tbh. Just email or comment with an offer. You will have to pay shipping up to $5 maximum.\r\n\r\nPAYMENT: Paypal or Ko-Fi\r\n\r\nLOCATION: Mid Michigan, USA (USD)\r\n\r\nDISPUTES: If there is a problem, contact me with the issue and a proposal and I will do my best to work this out.\r\n\r\nBUNDLES: If you want more than one item we may be able to bundle for a discount.<hr>\r\n<h2>LOT OF CLASSIC DOCTOR WHO BOOKS<\/h2> <img src=\"https:\/\/cupboard.alien.town\/raw\/tkL4uG.png\" alt=\"classic doctor who books stacked\" width=\"550\" height=\"302\">\r\n\r\nOnly some are pictured; there's at least 10 but probably more. Most are five or three era. Purchased in 2017 on eBay, never read most of them. Min $45 USD<hr><h2>JOURNAL\/PLANNER LOT<\/h2>\r\n<img src=\"https:\/\/cupboard.alien.town\/raw\/T1WvSS.png\" alt=\"2 journals and a planner\" width=\"550\" height=\"228\">\r\n\r\n2 journals, 1 planner. Min $10<hr><h2>INNOVIEW PORTABLE 15.6 INCH MONITOR<\/h2>\r\n<img src=\"https:\/\/cupboard.alien.town\/raw\/CXatkM.png\" alt=\"innoview 15.6 portable monitor\" width=\"550\" height=\"341\">\r\n\r\nCan include HDMI cables for an additional $5. Contact with any offer I just want it gone tbh.<hr>\r\n<h2>RIDICULOUSLY GAUDY PHOTO ALBUM<\/h2>\r\n\r\n<img src=\"https:\/\/cupboard.alien.town\/raw\/wzF03o.png\" alt=\"A white photo album with a thick plush cover and a giant gold heart in the middle it's covered with frills and lace\" width=\"296\" height=\"380\"><h2> <\/h2><hr><h1>MYSTERY LOTS<\/h1>\r\n\r\nAll items will be in good condition. There will be at least 5 items per lot. Send me an email or comment below with your interest in each lot and an offer as well as an email to contact, and I'll reach out to confirm and with an optional two revealed guaranteed items that will be in the package so you know if you want it or not. <h2>RANDOM #1: CARRIERS, ACCESSORIES, AND LIFESTYLE<\/h2><h2>RANDOM #2: PLUS SIZE WOMEN'S CLOTHING SIZES MOSTLY 2-4XL (QUIRKY\/GRANDMACORE\/MAXIMALIST\/FUNKY AESTHETICS MAINLY)<\/h2><h2>RANDOM #3: BOOKS<\/h2><h2>RANDOM #4:FIDGET TOYS<\/h2><h2>RANDOM #5: GENUINELY RANDOM STUFF WITH NO THEME<\/h2>","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-now.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073611,"title":"Now","content":"inspired by nownownow.com || Last Updated: Sept 19, 2026\r\n\r\nCURRENTLY…\r\n\r\nWatching: Strange New Worlds Season 3; Charmed season 4 (1998) & season 2 (2018); Farscape season 1\r\n\r\nReading: About to start Half His Age by Jenette McCurdy\r\n\r\nListening to: <a href=\"https:\/\/www.reddit.com\/r\/BrandNewSentence\/comments\/1c62noi\/i_was_raised_on_silk_shirt_rnb\/\">Silk Shirt R&B<\/a>\r\n\r\n<iframe style='height: 3.2cm;' src='https:\/\/scrobble.observer\/user\/keegbovo?theme=plain&dark'><\/iframe>\r\n\r\nPlaying: Sims 4, Tomodachi Life\r\n\r\nI recently remade my home on the IndieWeb for the billionth time, and am trying to get back into reading and writing with consistency, as well as trying to improve my digital art and embroidery skills! \r\n\r\nI got a new kitten in June and he’s so fun. I won free adoption for him! An absolute sweetheart.\r\n\r\nAugust was my one year anniversary of being with the first person my mostly-aromantic ass has ever truly loved and I feel super lucky to have them.\r\n\r\nI started my freshman year of college in late August as a religious studies major. I am 25, but never was able to attend before now due to chronic depression caused by a severe hormone sensitivity. I got treatment in July for it and it worked wonderfully; I’m ~~having surgery for those issues on September 11 to make the effects of the treatment permanent. A little nervous about the surgery because of my hEDS, but whatever. It will help me attend school and get me closer to my life goals overall, so it’s worth it.~~ I had the surgery and it went amazingly even if I was terribly nervous. I'm recovering pretty well now, though I miss being able to do things. My depression went from a constant nine out of ten absolute crisis mode at all times to only 3\/10 and I am very much enjoying having less depression!\r\n\r\nI started attending meetings of the Religious Society of Friends\/Quakers on August 30 202 and am now ~officially~ working towards becoming a member. \r\n\r\nI did some tech projects no one else has been able to figure out before, so that was fun. I’m proud of what I have learned about self-hosting and web development since I began this journey in 2024.\r\n\r\nI tried to learn how to ride a tricycle and realized that Vehicles Of Any Sort are not for me. So I'm finally beginning navigating the world using Uber, and doing things on my own when I can (previously I have been in too much pain to do a lot of things, but I am treating it better now.) Being able to have more autonomy has been good for me.\r\n\r\nI think that’s it for now!","description":"","status":"published","include_in_nav":"no"}
|
||||||
1
content/autosaves/page-uses.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"timestamp":1791073794,"title":"Uses","content":"# Things I Use\r\n\r\nInspired by uses.tech.\r\n\r\n<strong>What I Use For… a personal laptop:<\/strong> HP 15.6″ touchscreen business & home laptop, 8GB RAM, 512GB SSD, Windows 10\r\n\r\n<strong>What I Use For… an MP3 player:<\/strong> AiMoonsa MP3 player, 64GB, black<br \/>\r\n<strong>What I Use For… a digital calendar:<\/strong><a href=\"https:\/\/www.amazon.com\/dp\/B0FLDY5Q9D\" rel=\"nofollow\"> Anyuse 10.1″ digital calendar chore chart<\/a><br \/>\r\n<strong>What I Use For… TV and Media<\/strong>: 40″ onn. Roku TV, Panasonic DVD Bluray player, YOTON portable 9″ DVD player<br \/>\r\n<strong>What I Use For… a digital typewriter<\/strong>: Freewrite Alpha<br \/>\r\n<strong>What I Use For… a smart watch<\/strong><a href=\"https:\/\/www.amazon.com\/dp\/B0GPW96VPJ?th=1\" rel=\"nofollow\">Tesky smart watch<\/a><br \/>\r\n<strong>What I Use For.. drawing:<\/strong> XPPEN Updated Deco Mini7 V2 Tablet, IbispaintX<br \/>\r\n<strong>What I Use For… e-books<\/strong>: XTE Ink X4\/Kobo<br \/>\r\n<strong>What I Use For… gaming<\/strong>: Nintendo Switch<\/p>\r\n\r\n<p><strong>What I Use For… this site<\/strong>: PureBlog<br \/>\r\n<strong>What I Use For… servers<\/strong>:<\/p>\r\n\r\n(running list not up to date)\r\n\r\n<p>2x HP ProBooks, 8GB RAM, 512GB\/EA SSD || Runs: personal fediverse, piefed, beszel<\/p>\r\n\r\n<p>HP Envy, 12GB RAM, 1TB SSD || Runs: formerly Sunset, now nothing at the moment<\/p>\r\n\r\n<p>2x HP Pavilion, 16GB RAM, 1TB SSD || Runs: Cheesy, Rails sites, Fandom.Cooking, UptimeKuma, fanart archive<\/p>\r\n\r\n<p>2x Dell Inspiron All in one desktop, 64GB RAM, 4TB SSD | Runs: Dreamwidth clone, PHPbb forums, forgejo, BookWyrm, FreshRSS, LinkDing, SillyWordz, Status.cafe, personal archive, Ovumcy, Sunset<\/p>\r\n\r\n<p>HP 255 G10 Professional Business Laptop, 64GB RAM, 2TB SSD || Runs: this site<\/p>\r\n\r\n<p>This page is inspired by <a href=\"https:\/\/uses.tech\/\" rel=\"nofollow\">uses.tech<\/a><\/p>","description":"","status":"published","include_in_nav":"no"}
|
||||||