Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["blogPostTitle"]) && isset($_POST["blogPostContent"]) && isset($_POST["blogPostAuthor"])) {
$post['title'] = test_input($_POST["blogPostTitle"]);
$post['SEF_URL'] = preg_replace('/\s+/', '+', test_input($_POST["blogPostLink"]));
$post['author'] = test_input($_POST["blogPostAuthor"]);
$post['image'] = test_input($_POST["blogPostImageURL"]);
$post['password'] = test_input($_POST["blogPostPassword"]);
Expand Down Expand Up @@ -307,6 +308,7 @@
"title" => test_input($_POST["blogPostTitle"]),
"date" => time(),
"draft" => true,
"SEF_URL"=>preg_replace('/\s+/', '+', test_input($_POST["blogPostLink"])),
"author" => test_input($_POST["blogPostAuthor"]),
"content" => test_input($_POST["blogPostContent"]),
"password" => test_input($_POST["blogPostPassword"])
Expand Down Expand Up @@ -410,6 +412,37 @@
}
}, 'dashboard');

// Get Specific Post - Config file must exist, User does not need to be authenticated
$router->map('GET', '/[:SEF_URL]', function ($SEF_URL) {
global $router;
if (file_exists("config.php")) {
global $siteConfig;
global $blogStore;
global $Extra;

$post = $blogStore->findOneBy(["SEF_URL", "=", urldecode($SEF_URL)]);

if ($post == null) {
// Build out nice 404 page and header to it
echo ("404 Not Found");
} else {
$passAttempt = "";
if (isset($_REQUEST['password'])) {
$passAttempt = $_REQUEST['password'];
}
if (empty($post["password"]) || $passAttempt === $post["password"]) {
$pageTitle = $post['title'];
require __DIR__ . '/templates/' . $siteConfig['template'] . '/post.php';
} else {
$pageTitle = "Private post";
require __DIR__ . '/internal/private.php';
}
}
} else {
header("Location: " . $router->generate('settings'));
}
}, "SEF_URL");

$match = $router->matcher();

session_start();
Expand Down
4 changes: 2 additions & 2 deletions internal/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="post">
<div class="postText">
<h2 id="postTitle">
<a href="<?php echo $router->generate('post', ['id' => $dPost['_id']]); ?>"><?php echo $dPost['title']; ?></a>
<a href="<?= empty($dPost['SEF_URL']) ? $router->generate('post', ['id' => $dPost['_id']]) : $router->generate('SEF_URL', ['SEF_URL' => $dPost['SEF_URL']]) ?>"><?php echo $dPost['title']; ?></a>
</h2>
<?php i18n("dashboard_posted_by"); ?> <?php echo $dPost['author']; ?> - <?php echo date(i18n('dashboard_post_fulldate',false), $dPost['date']); ?>
<br>
Expand All @@ -41,7 +41,7 @@
<div class="post">
<div class="postText">
<h2 id="postTitle">
<a href="<?php echo $router->generate('post', ['id' => $pPost['_id']]); ?>"><?php echo $pPost['title']; ?></a>
<a href="<?= empty($pPost['SEF_URL']) ? $router->generate('post', ['id' => $pPost['_id']]) : $router->generate('SEF_URL', ['SEF_URL' => $pPost['SEF_URL']]) ?>"><?php echo $pPost['title']; ?></a>
</h2>
<?php i18n("dashboard_posted_by"); ?> <?php echo $pPost['author']; ?> - <?php echo date(i18n('dashboard_post_fulldate',false), $pPost['date']); ?>
<br>
Expand Down
4 changes: 3 additions & 1 deletion internal/i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"write_title" => "Time to write your prose",
"write_post_title_placeholder" => "The post title",
"write_post_author_placeholder" => "The post author",
"write_post_link_placeholder" => "Link to this post",
"write_post_image_placeholder" => "A featured image for this post",
"write_post_password_placeholder" => "Password if you want to hide the post",
"write_post_markdown_placeholder" => "Write your post here, you can use Markdown",
Expand Down Expand Up @@ -163,7 +164,7 @@
"dashboard_draft_post" => "Чернетки дописів:",
"dashboard_published_post" => "Опубліковані дописи:",
"dashboard_posted_by" => "Опубліковано:",
"dashboard_post_fulldate" => "F d, Y @ g:i A",
"dashboard_post_fulldate" => "H:i d.m.Y",
"dashboard_publish" => "Опублікувати",
"dashboard_draft" => "Створити чернетку",
"dashboard_edit" => "Змінити",
Expand All @@ -179,6 +180,7 @@
"write_title" => "Створення/редагування допису",
"write_post_title_placeholder" => "Назва",
"write_post_author_placeholder" => "Автор",
"write_post_link_placeholder" => "Посилання на цей допис",
"write_post_image_placeholder" => "Рекомендоване зображення для цього допису",
"write_post_password_placeholder" => "Пароль, якщо ви хочете приховати публікацію",
"write_post_markdown_placeholder" => "Напишіть свій допис тут, ви можете використовувати Markdown",
Expand Down
3 changes: 3 additions & 0 deletions internal/write.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<input type="text" name="blogPostAuthor" class="blogPostAuthor" placeholder="<?php i18n("write_post_author_placeholder"); ?>" required value="<?php if (isset($post['author'])) {
echo $post['author'];
} ?>" />
<input type="text" name="blogPostLink" class="blogPostLink" placeholder="<?php i18n("write_post_link_placeholder"); ?>" value="<?php if (isset($post['SEF_URL'])) {
echo $post['SEF_URL'];
} ?>" />
<input type="url" name="blogPostImageURL" class="blogPostImageURL" placeholder="<?php i18n("write_post_image_placeholder"); ?>" value="<?php if (isset($post['image'])) {
if (is_numeric($post['image']) == TRUE) {
$databaseDirectory = "./siteDatabase";
Expand Down
4 changes: 2 additions & 2 deletions templates/liquid-new/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
echo '<img class="card-img-top" src="' . $siteConfig["OGImage"] . '">';
}?>
<div class="card-body">
<a href="<?php echo $router->generate('post', ['id' => $post['_id']]); ?>" class="text-decoration-none text-dark">
<h3 class="card-title"><?php echo $post['title']; ?></h3>
<a href="<?= empty($post['SEF_URL']) ? $router->generate('post', ['id' => $post['_id']]) : $router->generate('SEF_URL', ['SEF_URL' => $post['SEF_URL']]) ?>" class="text-decoration-none text-dark">
<h3 class="card-title"><?= $post['title']; ?></h3>
</a>
<?php
if ($post['password'] != '') { ?>
Expand Down