85 lines
2.0 KiB
PHP
85 lines
2.0 KiB
PHP
<?php
|
|
|
|
$data = array_merge($data, [
|
|
'title' => 'Novaconium Edit Page',
|
|
'pageclass' => 'novaconium',
|
|
'editor' => 'ace'
|
|
]);
|
|
|
|
// Check if logged in
|
|
if (empty($session->get('username'))) {
|
|
$messages->error('You are not logged in');
|
|
$redirect->url('/novaconium/login');
|
|
makeitso();
|
|
}
|
|
|
|
// Get page ID from router parameters
|
|
$pageid = $router->parameters['id'] ?? null;
|
|
|
|
if (!empty($pageid)) {
|
|
// Existing page: fetch from database
|
|
$query = <<<EOSQL
|
|
WITH all_tags AS (
|
|
SELECT GROUP_CONCAT(DISTINCT name ORDER BY name SEPARATOR ',') AS tags_list
|
|
FROM tags
|
|
)
|
|
SELECT
|
|
p.id,
|
|
p.title,
|
|
p.heading,
|
|
p.description,
|
|
p.keywords,
|
|
p.author,
|
|
p.slug,
|
|
p.path,
|
|
p.intro,
|
|
p.body,
|
|
p.notes,
|
|
p.draft,
|
|
p.changefreq,
|
|
p.priority,
|
|
p.created,
|
|
p.updated,
|
|
COALESCE(GROUP_CONCAT(DISTINCT t.name ORDER BY t.name SEPARATOR ','), '') AS page_tags,
|
|
at.tags_list AS existing_tags
|
|
FROM pages p
|
|
LEFT JOIN page_tags pt ON p.id = pt.page_id
|
|
LEFT JOIN tags t ON pt.tag_id = t.id
|
|
CROSS JOIN all_tags at -- Zero-cost join for scalar
|
|
WHERE p.id = ?
|
|
GROUP BY p.id;
|
|
EOSQL;
|
|
|
|
$data['rows'] = $db->getRow($query, [$pageid]);
|
|
|
|
// If no row is found, treat as new page
|
|
if (!$data['rows']) {
|
|
$pageid = null;
|
|
}
|
|
}
|
|
|
|
if (empty($pageid)) {
|
|
// New page: set default values for all fields
|
|
$data['rows'] = [
|
|
'id' => 'newpage',
|
|
'title' => '',
|
|
'heading' => '',
|
|
'description' => '',
|
|
'keywords' => '',
|
|
'author' => $session->get('username') ?? '',
|
|
'slug' => '',
|
|
'path' => '',
|
|
'intro' => '',
|
|
'body' => '',
|
|
'notes' => '',
|
|
'draft' => 0,
|
|
'changefreq' => 'monthly',
|
|
'priority' => 0.0,
|
|
'created' => date('Y-m-d H:i:s'),
|
|
'updated' => date('Y-m-d H:i:s')
|
|
];
|
|
}
|
|
|
|
// Render the edit page view
|
|
view('@novacore/editpage/index', $data);
|