$template_variables['post_slug'] = '';
$template_variables['post_date'] = '';
$template_variables['post_data'] = '';
+ $template_variables['post_is_page'] = false;
$template_variables['post_is_draft'] = true;
-
$template_class = 'admin';
$template = 'post';
$template_variables['post_slug'] = $post->slug;
$template_variables['post_date'] = $post->date;
$template_variables['post_data'] = $post->data;
+ $template_variables['post_is_page'] = $post->is_page;
$template_variables['post_is_draft'] = $post->is_draft;
$template_class = 'admin';
if (isset($slug) == false) $slug = null;
$date = cx_form_input_sanitized_date_time('post_date');
if (isset($date) == false) $date = null;
+ $page = cx_form_input_sanitized('post_is_page') == 'page';
$draft = cx_form_input_sanitized('post_is_draft') == 'draft';
$data = cx_form_input_sanitized_allowing_html('post_data');
if (isset($_GET['id']) == false or $_GET['id'] == 0) {
- cx_posts_add_post(1, $title, $slug, $date, $draft, $data);
+ cx_posts_add_post(1, $title, $slug, $date, $page, $draft, $data);
} else {
$id = $_GET['id'];
- cx_posts_update_post($id, $title, $slug, $date, $draft, $data);
+ cx_posts_update_post($id, $title, $slug, $date, $page, $draft, $data);
}
cx_http_redirect(cx_url_admin('/'));
$template = 'list';
$template_variables['page_number'] = $page_number;
- } else if (count($path_components) >= 3) { // FIXME sometime, needs more flexibility...
- $year = $path_components[0];
- $month = $path_components[1];
- $slug = $path_components[2];
+ } else {
+ if (count($path_components) >= 1) {
+ $slug = $path_components[0];
+ $page_id = cx_posts_find_page_id($slug);
+ if ($page_id) {
+ $template = 'post';
+ $template_variables['post_id'] = cx_posts_find_page_id($slug);
+ }
+ }
- $template = 'post';
- $template_variables['post_id'] = cx_posts_find_post_id($slug);
+ if ($template == null && count($path_components) >= 3) { // FIXME sometime, needs more flexibility...
+ $year = $path_components[0];
+ $month = $path_components[1];
+ $slug = $path_components[2];
+ $post_id = cx_posts_find_article_id($slug);
+ if ($post_id) {
+ $template = 'post';
+ $template_variables['post_id'] = cx_posts_find_article_id($slug);
+ }
+ }
}
-
+
if ($template != null) {
$output = cx_template_render($template_class, $template, $template_variables);
echo($output);
return $slug;
}
-function cx_posts_add_post($site_id, $title, $slug, $date, $draft, $data) {
+function cx_posts_add_post($site_id, $title, $slug, $date, $page, $draft, $data) {
$creation_time = $update_time = time();
if ($slug == null) {
post_data,
post_data_version)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
- cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, false, $draft, $title, $data, 1);
+ cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, $page, $draft, $title, $data, 1);
}
-function cx_posts_update_post($post_id, $title, $slug, $date, $draft, $data) {
+function cx_posts_update_post($post_id, $title, $slug, $date, $page, $draft, $data) {
$update_time = time();
if ($slug == null) {
SET post_update_time = ?,
post_slug = ?,
post_date = ?,
+ post_is_page = ?,
post_is_draft = ?,
post_title = ?,
post_data = ?
WHERE post_id == ?;';
//LIMIT 1;';
- cx_db_exec($sql, $update_time, $slug, $date, $draft, $title, $data, $post_id);
+ cx_db_exec($sql, $update_time, $slug, $date, $page, $draft, $title, $data, $post_id);
}
function cx_posts_delete_post($post_id) {
post_title,
post_data
FROM posts
- WHERE post_is_page == FALSE
- AND post_id == ?
+ WHERE post_id == ?
LIMIT 1;';
foreach (cx_db_query($sql, $post_id) as $post) {
return null;
}
-function cx_posts_find_post_id($post_slug) {
+function cx_posts_find_article_id($post_slug) {
$sql = 'SELECT
post_id
FROM posts
WHERE post_slug == ?
+ AND post_is_page == FALSE
+ AND post_is_draft == FALSE
+ LIMIT 1;';
+
+ foreach (cx_db_query($sql, $post_slug) as $post) {
+ return $post['post_id'];
+ }
+
+ return null;
+}
+
+function cx_posts_find_page_id($post_slug) {
+ $sql = 'SELECT
+ post_id
+ FROM posts
+ WHERE post_slug == ?
+ AND post_is_page == TRUE
+ AND post_is_draft == FALSE
LIMIT 1;';
foreach (cx_db_query($sql, $post_slug) as $post) {
<p>title: <input name="post_title" type="text" value="<?= $post_title ?>"></p>
<p>slug: <input name="post_slug" type="text" value="<?= $post_slug ?>"></p>
<p>date: <input name="post_date" type="text" value="<?= $post_date ? date('Y-m-d H:i:s', $post_date) : "" ?>"></p>
+<p>page: <input name="post_is_page" type="checkbox" value="page" <?= $post_is_page ? "checked" : "" ?>></p>
<p>draft: <input name="post_is_draft" type="checkbox" value="draft" <?= $post_is_draft ? "checked" : "" ?>></p>
<p><textarea name="post_data" cols="60" rows="40"><?= $post_data ?></textarea></p>
<p>Find me <a href="https://mastodon.gamedev.place/@btsherratt" rel="me">@btsherratt</a> or on <a href="https://bts.itch.io/">itch.io</a></p>
</header>
-<?php /*<nav>
+<nav>
<ul role="list">
<li><a href="<?= cx_url('/'); ?>">Home</a></li>
<?php foreach (cx_pages_get() as $page): ?>
-<li><a href="<?= cx_url($page->url); ?>"><?= $page->title ?></a></li>
+<li><a href="<?= cx_url('/' . $page->slug); ?>"><?= $page->title ?></a></li>
<?php endforeach; ?>
</ul>
-</nav> */ ?>
+</nav>
<?= cx_template_content(); ?>
/* Layout */
body {
+ background: #fcfcfc;
display: flex;
flex-direction: column;
min-height: 100vh;
margin-right: auto;
}
-header {
- margin-bottom: 8vh;
-}
-
header h1 {
font-size: 2em;
}
text-decoration: none;
}
+header p {
+ font-size: 0.8em;
+}
+
+nav {
+ margin-top: 2vh;
+ margin-bottom: 4vh;
+}
+
nav ul {
list-style: none;
display: flex;
text-underline-offset: 0.08em;
}
+a:hover {
+ background-color: navy;
+ color: #fcfcfc;
+}
+
a:focus {
outline: 1px solid currentColor;
outline-offset: 0.2em;