From 673771dd27cc3fec528fce3bad71758e9210a4aa Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 27 May 2017 11:45:08 +0200 Subject: [PATCH] Added an RSS news feed for blog posts --- blog.php | 50 ++++++++++++++++++++++++++++++++++++++------------ img/rss.svg | 30 ++++++++++++++++++++++++++++++ index.php | 9 +++++++-- rss.php | 40 ++++++++++++++++++++++++++++++++++++++++ shared.php | 10 ++++++++++ 5 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 img/rss.svg create mode 100644 rss.php diff --git a/blog.php b/blog.php index 8166c4f..56bd85f 100644 --- a/blog.php +++ b/blog.php @@ -69,6 +69,7 @@ global $pageTitle; global $postUrl; global $htmlHead; + global $CMS_RSS; $counters['figure'] = 1; $counters['video'] = 1; @@ -95,12 +96,12 @@ $blogentry->tags = explode(',', $blogentry->tags); sort($blogentry->tags); - $blogentry->permalink = "?p=blog&b=" . str_replace("/", POSTS_DIR_SEP, $blogentry->file); + $blogentry->permalink = getServerUrl() . "/?p=blog&b=" . str_replace("/", POSTS_DIR_SEP, $blogentry->file); $blogentry->isPublic = ($blogentry->status == "released"); } $renderIt = $CMS_INDEXING || ($blogentry->status == "released") || ($blogentry->status == "unlisted"); - if ($renderIt) { + if ($renderIt && !isset($CMS_RSS)) { if (isset($postUrl) && !$CMS_INDEXING) { // Set meta information $pageTitle = $blogentry->title; $htmlHead .= ' @@ -212,7 +213,8 @@ } - echo ""; + if (!isset($CMS_RSS)) + echo ""; if (isset($postUrl)) { // Display post $CMS_SINGLE_POST = true; echo '
'; @@ -227,21 +229,44 @@ else { //echo "

Blog posts

"; if (isset($tagSearch)) { - echo "

Archive for '$tagSearch'

"; + echo "

"; + if (RSS_ENABLED) { + echo ''; + } + echo '
Archive for '$tagSearch'

'; $pageTitle = "Archive for '$tagSearch'"; } + if (isset($CMS_RSS) && RSS_SHOW_FULL) { + $CMS_SINGLE_POST = true; + } $i = 0; $morePosts = false; foreach($posts as $k=>$v) { if ($v->isPublic) { if (!isset($tagSearch) || in_array($tagSearch, $v->tags)) { if ($i++ >= $postsSkip) { - //echo "permalink\">$v->title by $v->author
"; - echo '
'; - require $v->includeFile; - renderFooter(); - echo "
"; - echo '
'; + if (isset($CMS_RSS)) { + if (!isset($latestDisplayedPost)) { + $latestDisplayedPost = $v->ctime; + } + echo ' + ' . $v->title . ' + includeFile; + renderFooter(); + echo ']]> + permalink . ']]> + permalink . ']]> + ' . date($RSS_DATE_FORMAT, $v->ctime) . ' + ' . $v->author . ' +'; + } else { + echo '
'; + require $v->includeFile; + renderFooter(); + echo "
"; + echo '
'; + } if (($i % POSTS_PAGE_SIZE) == 0) { $morePosts = true; break; @@ -258,6 +283,7 @@ echo 'Newer posts >>'; if ($morePosts || $postsSkip > 0) echo "

"; - } - echo ""; + } + if (!isset($CMS_RSS)) + echo ""; ?> diff --git a/img/rss.svg b/img/rss.svg new file mode 100644 index 0000000..18ee398 --- /dev/null +++ b/img/rss.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/index.php b/index.php index 0ddc347..53fb6b3 100644 --- a/index.php +++ b/index.php @@ -71,9 +71,14 @@
diff --git a/rss.php b/rss.php new file mode 100644 index 0000000..c7819d0 --- /dev/null +++ b/rss.php @@ -0,0 +1,40 @@ + + + + + ' . PAGE_NAME . $tagSearchTitle . ' + + ' . getServerUrl() . ' + ' . date($RSS_DATE_FORMAT, $latestDisplayedPost) . ' + ' . date($RSS_DATE_FORMAT, $latestDisplayedPost) . ' + ' . RSS_REFRESH_INTERVAL . ' + + ' . $output; + return $output; + }); + + require "blog.php"; + echo ''; + } +?> diff --git a/shared.php b/shared.php index 1e7fa56..cf32611 100644 --- a/shared.php +++ b/shared.php @@ -11,6 +11,10 @@ define('POSTS_DIR_SEP', "."); // Directory separator (/) in post names define('POSTS_MAX_FILENAME', 30); // Maximum length of a post name (including suffix) define('POSTS_TAG_SEARCH', 30); // Maximum length for the tag search argument + + define('RSS_ENABLED', true); // Enable the RSS news feed + define('RSS_REFRESH_INTERVAL', 14400); // Advertised update interval for the RSS feed + define('RSS_SHOW_FULL', false); // Show extended section in RSS feed $menuItems = array( array("label" => "Page A", "link" => "?p=00-template", "highlight" => "related-subpages,00-template"), @@ -135,4 +139,10 @@ return $counters['sources']++; } } + + function getServerUrl() { + $temp = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; + $temp .= $_SERVER['HTTP_HOST']; + return $temp; + } ?>