diff --git a/.gitignore b/.gitignore index 5b23378..16610a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /fcgid-bin/ /docs/common/config.php /assets/upload/** +/docs/www/blog/feed.atom diff --git a/docs/www/blog/index.php b/docs/www/blog/index.php index b27b8a8..a3d914b 100755 --- a/docs/www/blog/index.php +++ b/docs/www/blog/index.php @@ -110,6 +110,15 @@ display_header("Blogs"); 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.

+

+ + + Recent blogposts get posted to + + my atom feed. +


diff --git a/docs/www/blog/writearticle.php b/docs/www/blog/writearticle.php index 5cc4ab5..b76e34d 100644 --- a/docs/www/blog/writearticle.php +++ b/docs/www/blog/writearticle.php @@ -13,6 +13,106 @@ if (!isset($_COOKIE["PHPSESSID"]) || die(); } +/** + * Generate a feed.atom file for use by atom/rss readers. + */ +function generate_atom_feed($conn) { + if (!($fp = fopen('feed.atom', 'w'))) { + return; + } + + // Prepare statement for selecting all the blogposts + $stmt = $conn->prepare("SELECT blogpost_id, readable_address, title, + abstract, content, date_posted, date_edited FROM blogposts ORDER BY + date_posted DESC LIMIT 15;"); + + // Execute the statement + $stmt->execute(); + + // Prepare new statement for selecting the tags for a given blogpost + $blogposts_arr = $stmt->fetchall(PDO::FETCH_ASSOC); + + fprintf($fp, " + + Zdenek Borovec blog + + %s + + Zdenek Borovec + + https://www.zenekborovec.cz/blog/ + ", date("Y-m-d\TH:i:s\Z")); + + // Prepare new statement for selecting the tags for a given blogpost + $stmt = $conn->prepare("SELECT name 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); + + $categoryStr = ""; + + for($j=0; $j < count($tags_arr); $j++) { + $tag = $tags_arr[$j]; + $categoryStr = $categoryStr.""; + } + + if(is_null($blog["readable_address"])) { + fprintf($fp, " + + %s + %s + + urn:uuid:%s + %s + %s + %s + + %s + + ", $blog["title"], $categoryStr, $blog["blogpost_id"], + $blog["blogpost_id"], + date("Y-m-d\TH:i:s\Z", strtotime($blog["date_posted"])), + date("Y-m-d\TH:i:s\Z", strtotime($blog["date_edited"])), + $blog["abstract"], sanitize_input($blog["content"])); + } + else { + fprintf($fp, " + + %s + %s + + urn:uuid:%s + %s + %s + %s + + %s + + ", $blog["title"], $categoryStr, $blog["readable_address"], + $blog["blogpost_id"], + date("Y-m-d\TH:i:s\Z", strtotime($blog["date_posted"])), + date("Y-m-d\TH:i:s\Z", strtotime($blog["date_edited"])), + $blog["abstract"], sanitize_input($blog["content"])); + } + } + fprintf($fp, ""); +} + /** * Explode the tag string into separate tags, if they exist, * attach them to the article. @@ -166,7 +266,10 @@ if(isset($_POST["submit"])) { $content); } - header("Location: "."http://www.zdenekborovec-dev.cz/blog"); + generate_atom_feed($conn); + + header("Location: http://www.zdenekborovec-dev.cz/blog"); + die(); } if(isset($_GET["guid"])) {