2023-12-21 13:11:22 +01:00
|
|
|
<?php
|
2024-05-10 17:20:25 +02:00
|
|
|
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
|
|
|
|
|
|
|
|
include_once($COMMONS."/header.php");
|
|
|
|
|
2024-04-28 15:21:09 +02:00
|
|
|
/**
|
|
|
|
* Display a blog-preview div
|
|
|
|
*/
|
2024-07-20 14:12:19 +02:00
|
|
|
function display_blog_preview($blogpost_id, $blogpost_addr, $title, $abstract,
|
2024-04-28 15:21:09 +02:00
|
|
|
$date_posted, $tags){
|
2024-08-22 00:06:44 +02:00
|
|
|
print_r("
|
2024-04-28 15:21:09 +02:00
|
|
|
<div class=\"blog-preview\">
|
2024-08-22 00:06:44 +02:00
|
|
|
<table class=\"noborder-table\" style=\"width: 100%;\">
|
|
|
|
<tr><td>");
|
2024-07-20 14:12:19 +02:00
|
|
|
printf("
|
2024-07-31 06:31:31 +02:00
|
|
|
<a href=\"http://www.zdenekborovec-dev.cz/blog/article/%s\">
|
2024-07-20 14:12:19 +02:00
|
|
|
<h3>
|
|
|
|
%s
|
|
|
|
</h3>
|
2024-08-22 00:06:44 +02:00
|
|
|
</a></td>
|
2024-07-20 14:12:19 +02:00
|
|
|
", $blogpost_addr, $title);
|
2024-08-22 00:06:44 +02:00
|
|
|
|
|
|
|
if (isset($_COOKIE["PHPSESSID"]) &&
|
|
|
|
(bool)($_SESSION["current_user"]->permissions & 128)) {
|
|
|
|
print_r("<td style=\"display: inline-block; text-align: right;
|
|
|
|
width: 100%;\">");
|
|
|
|
printf("<a
|
|
|
|
href=\"http://www.zdenekborovec-dev.cz/blog/writearticle?guid=%s\"
|
|
|
|
style=\"border: dotted black;\">edit</a></td>", $blogpost_id);
|
2024-07-20 14:12:19 +02:00
|
|
|
}
|
2024-08-22 00:06:44 +02:00
|
|
|
print_r("</tr></table>");
|
2024-04-28 15:21:09 +02:00
|
|
|
|
2024-05-13 00:03:56 +02:00
|
|
|
print_r("<table class=\"noborder-table\" style=\"width: 100%;\">
|
|
|
|
<tr><td class=\"blog-tags\">");
|
|
|
|
|
2024-04-28 15:21:09 +02:00
|
|
|
for($i = 0; $i < count($tags); $i++) {
|
|
|
|
$tag = $tags[$i];
|
|
|
|
printf("
|
|
|
|
<span class=\"blog-tag\" style=\"background-color: %s\">
|
|
|
|
%s
|
|
|
|
</span>", $tag["color"], $tag["name"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("
|
2024-05-13 00:03:56 +02:00
|
|
|
</td><td class=\"blog-publish-date\">
|
2024-04-28 15:21:09 +02:00
|
|
|
Published on: %s
|
2024-05-13 00:03:56 +02:00
|
|
|
</td></tr></table>
|
2024-05-12 23:13:40 +02:00
|
|
|
<hr>
|
2024-04-28 15:21:09 +02:00
|
|
|
<p>
|
|
|
|
%s
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
", date("Y-m-d", strtotime($date_posted)), $abstract);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select all the blogposts from the database, their tags, then display them.
|
|
|
|
*/
|
2024-05-08 16:00:44 +02:00
|
|
|
function display_blog_previews($conn){
|
2024-04-28 15:21:09 +02:00
|
|
|
// Check DB connection
|
|
|
|
if($conn == null){
|
2024-05-10 17:20:25 +02:00
|
|
|
header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable", true, 503);
|
|
|
|
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/503.php");
|
|
|
|
include_once($COMMONS."/footer.php");
|
2024-05-08 16:00:44 +02:00
|
|
|
die();
|
2024-04-28 15:21:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare statement for selecting all the blogposts
|
2024-07-20 14:12:19 +02:00
|
|
|
$stmt = $conn->prepare("SELECT blogpost_id, readable_address, title,
|
|
|
|
abstract, date_posted FROM blogposts ORDER BY date_posted DESC;");
|
2024-04-28 15:21:09 +02:00
|
|
|
|
|
|
|
// Execute the statement
|
|
|
|
$stmt->execute();
|
|
|
|
|
|
|
|
// Fetch the blogposts
|
|
|
|
$blogposts_arr = $stmt->fetchall(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
// Prepare new statement for selecting the tags for a given blogpost
|
|
|
|
$stmt = $conn->prepare("SELECT name, color FROM
|
|
|
|
blogpost_tags INNER JOIN blogpost_has_tag ON
|
|
|
|
blogpost_tags.tag_id = blogpost_has_tag.tag_id WHERE
|
|
|
|
blogpost_id = :blogpost_id;");
|
|
|
|
|
|
|
|
// Go through all the blogposts, fetch their tags and display them
|
|
|
|
for($i = 0; $i < count($blogposts_arr); $i++) {
|
|
|
|
// Get info for the current blog
|
|
|
|
$blog = $blogposts_arr[$i];
|
|
|
|
|
|
|
|
// Bind and execute the tag select
|
|
|
|
$stmt->bindParam(":blogpost_id", $blog["blogpost_id"]);
|
|
|
|
$stmt->execute();
|
|
|
|
|
|
|
|
// Fetch the tags
|
|
|
|
$tags_arr = $stmt->fetchall(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
// Display the blog
|
2024-07-20 14:12:19 +02:00
|
|
|
display_blog_preview($blog["blogpost_id"], $blog["readable_address"],
|
|
|
|
$blog["title"], $blog["abstract"], $blog["date_posted"],
|
|
|
|
$tags_arr);
|
2024-04-28 15:21:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:00:44 +02:00
|
|
|
display_header("Blogs");
|
2023-12-21 13:11:22 +01:00
|
|
|
?>
|
|
|
|
|
|
|
|
<article>
|
2024-01-19 04:17:10 +01:00
|
|
|
<h2>
|
|
|
|
My blogposts
|
|
|
|
</h2>
|
|
|
|
<p>
|
2024-04-28 15:21:09 +02:00
|
|
|
These can range from well thought out slow-burning blood-churning gems
|
|
|
|
to random brain farts in textual form, you can use tags to filter.
|
2024-01-19 04:17:10 +01:00
|
|
|
</p>
|
2024-07-21 00:04:51 +02:00
|
|
|
<p>
|
|
|
|
<a href="http://www.zdenekborovec-dev.cz/blog/feed.atom">
|
|
|
|
<img src="https://assets.zdenekborovec.cz/upload/
|
|
|
|
4d8e8ce6d40218d86b2d4054cd02fe7f/22db7ac10bc3065f3dea6d797c51c627/
|
|
|
|
cd27fb6e76320b6f5ebe9ab951042ff3.png" style="height: 1em;"/></a>
|
|
|
|
Recent blogposts get posted to
|
|
|
|
<a href="http://www.zdenekborovec-dev.cz/blog/feed.atom">
|
|
|
|
my atom feed.</a>
|
|
|
|
</p>
|
2023-12-21 13:11:22 +01:00
|
|
|
</article>
|
2024-01-19 04:17:10 +01:00
|
|
|
<hr>
|
2023-12-21 13:11:22 +01:00
|
|
|
|
|
|
|
<?php
|
2024-05-08 16:00:44 +02:00
|
|
|
display_blog_previews($conn);
|
2024-05-10 17:20:25 +02:00
|
|
|
|
|
|
|
include_once($COMMONS."/footer.php");
|
2023-12-21 13:11:22 +01:00
|
|
|
?>
|