diff --git a/system/admin/admin.php b/system/admin/admin.php index 70d24f7..ea24f45 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1214,6 +1214,74 @@ function rename_category_folder($new_name, $old_file) } +// Find draft. +function find_draft($year, $month, $name) +{ + $posts = get_draft_posts(); + + foreach ($posts as $index => $v) { + $arr = explode('_', $v['basename']); + if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_posts($posts, $index + 1, 1); + $nx = get_posts($posts, $index, 1); + $pr = get_posts($posts, $index + 2, 1); + + if ($index == 0) { + if (isset($pr[0])) { + return array( + 'current' => $ar[0], + 'prev' => $pr[0] + ); + } else { + return array( + 'current' => $ar[0], + 'prev' => null + ); + } + } elseif (count($posts) == $index + 1) { + return array( + 'current' => $ar[0], + 'next' => $nx[0] + ); + } else { + return array( + 'current' => $ar[0], + 'next' => $nx[0], + 'prev' => $pr[0] + ); + } + } + } +} + +// Return draft list +function get_draft($profile, $page, $perpage) +{ + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + $posts = get_draft_posts(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + $str = explode('/', $v['dirname']); + if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { + $tmp[] = $v; + } + } + + if (empty($tmp)) { + return false; + } + + return $tmp = get_posts($tmp, $page, $perpage); +} + // Return draft static page. function find_draft_page($static = null) { @@ -1319,3 +1387,71 @@ function find_draft_subpage($sub_static = null) return $tmp; } + +// Find scheduled post. +function find_scheduled($year, $month, $name) +{ + $posts = get_scheduled_posts(); + + foreach ($posts as $index => $v) { + $arr = explode('_', $v['basename']); + if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_posts($posts, $index + 1, 1); + $nx = get_posts($posts, $index, 1); + $pr = get_posts($posts, $index + 2, 1); + + if ($index == 0) { + if (isset($pr[0])) { + return array( + 'current' => $ar[0], + 'prev' => $pr[0] + ); + } else { + return array( + 'current' => $ar[0], + 'prev' => null + ); + } + } elseif (count($posts) == $index + 1) { + return array( + 'current' => $ar[0], + 'next' => $nx[0] + ); + } else { + return array( + 'current' => $ar[0], + 'next' => $nx[0], + 'prev' => $pr[0] + ); + } + } + } +} + +// Return scheduled list +function get_scheduled($profile, $page, $perpage) +{ + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + $posts = get_scheduled_posts(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + $str = explode('/', $v['dirname']); + if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { + $tmp[] = $v; + } + } + + if (empty($tmp)) { + return false; + } + + return $tmp = get_posts($tmp, $page, $perpage); +} diff --git a/system/htmly.php b/system/htmly.php index dd9c8d9..69be11c 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -243,8 +243,8 @@ get('/author/:name', function ($name) { if (empty($posts) || $page < 1) { render($pview, array( 'title' => i18n('Profile_for') . ' ' . $author->name . ' - ' . blog_title(), - 'description' => get_description($author->about), - 'canonical' => site_url() . 'author/' . $name, + 'description' => $author->description, + 'canonical' => $author->url, 'page' => $page, 'posts' => null, 'about' => $author->about, @@ -260,8 +260,8 @@ get('/author/:name', function ($name) { render($pview, array( 'title' => i18n('Profile_for') . ' ' . $author->name . ' - ' . blog_title(), - 'description' => get_description($author->about), - 'canonical' => site_url() . 'author/' . $name, + 'description' => $author->description, + 'canonical' => $author->url, 'page' => $page, 'posts' => $posts, 'about' => $author->about, @@ -274,6 +274,25 @@ get('/author/:name', function ($name) { ), $layout); }); +// Show the RSS feed +get('/author/:name/feed', function ($name) { + + header('Content-Type: application/rss+xml'); + + $posts = get_profile_posts($name, 1, config('rss.count')); + + $author = get_author($name); + + if (isset($author[0])) { + $author = $author[0]; + } else { + $author = default_profile($name); + } + + // Show an RSS feed + echo generate_rss($posts, $author); +}); + // Edit the profile get('/edit/profile', function () { @@ -1863,6 +1882,25 @@ get('/category/:category', function ($category) { ), $layout); }); +// Show the RSS feed +get('/category/:category/feed', function ($category) { + + header('Content-Type: application/rss+xml'); + + $posts = get_category($category, 1, config('rss.count')); + + $data = get_category_info($category); + + if(strtolower($category) !== 'uncategorized') { + if(!empty($data)) { + $data = $data[0]; + } + } + + // Show an RSS feed + echo generate_rss($posts, $data); +}); + // Show edit the category page get('/category/:category/edit', function ($category) { @@ -2018,7 +2056,7 @@ get('/type/:type', function ($type) { $ttype->title = ucfirst($type); $ttype->url = site_url() . 'type/' . strtolower($type); $ttype->count = $total; - $ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title() . '.'; + $ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title(); if (empty($posts) || $page < 1) { // a non-existing page @@ -2049,7 +2087,7 @@ get('/type/:type', function ($type) { render($pview, array( 'title' => i18n('Posts_with_type') . ' ' . ucfirst($type) . ' - ' . blog_title(), - 'description' => i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title() . '.', + 'description' => i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title(), 'canonical' => site_url() . 'type/' . strtolower($type), 'page' => $page, 'posts' => $posts, @@ -2061,6 +2099,21 @@ get('/type/:type', function ($type) { ), $layout); }); +// Show the RSS feed +get('/type/:type/feed', function ($type) { + + header('Content-Type: application/rss+xml'); + + $posts = get_type($type, 1, config('rss.count')); + $data = new stdClass; + $data->title = ucfirst($type); + $data->url = site_url() . 'type/' . strtolower($type); + $data->body = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title(); + + // Show an RSS feed + echo generate_rss($posts, $data); +}); + // Show the tag page get('/tag/:tag', function ($tag) { @@ -2086,7 +2139,7 @@ get('/tag/:tag', function ($tag) { $ttag->title = tag_i18n($tag); $ttag->url = site_url() . 'tag/' . strtolower($tag); $ttag->count = $total; - $ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title() . '.'; + $ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title(); if (empty($posts) || $page < 1) { // a non-existing page @@ -2117,7 +2170,7 @@ get('/tag/:tag', function ($tag) { render($pview, array( 'title' => i18n('Posts_tagged') . ' ' . tag_i18n($tag) . ' - ' . blog_title(), - 'description' => i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title() . '.', + 'description' => i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title(), 'canonical' => site_url() . 'tag/' . strtolower($tag), 'page' => $page, 'posts' => $posts, @@ -2129,6 +2182,21 @@ get('/tag/:tag', function ($tag) { ), $layout); }); +// Show the RSS feed +get('/tag/:tag/feed', function ($tag) { + + header('Content-Type: application/rss+xml'); + + $posts = get_tag($tag, 1, config('rss.count')); + $data = new stdClass; + $data->title = tag_i18n($tag); + $data->url = site_url() . 'tag/' . strtolower($tag); + $data->body = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title(); + + // Show an RSS feed + echo generate_rss($posts, $data); +}); + // Show the archive page get('/archive/:req', function ($req) { @@ -2170,7 +2238,7 @@ get('/archive/:req', function ($req) { $tarchive->title = $timestamp; $tarchive->url = site_url() . 'archive/' . $req; $tarchive->count = $total; - $tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title() . '.'; + $tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title(); if (!$date) { // a non-existing page @@ -2195,7 +2263,7 @@ get('/archive/:req', function ($req) { render($pview, array( 'title' => i18n('Archive_for') . ' ' . $timestamp . ' - ' . blog_title(), - 'description' => i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title() . '.', + 'description' => i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title(), 'canonical' => site_url() . 'archive/' . $req, 'page' => $page, 'posts' => $posts, @@ -2207,6 +2275,33 @@ get('/archive/:req', function ($req) { ), $layout); }); +// Show the RSS feed +get('/archive/:req/feed', function ($req) { + + header('Content-Type: application/rss+xml'); + + $posts = get_archive($req, 1, config('rss.count')); + + $time = explode('-', $req); + $date = strtotime($req); + + if (isset($time[0]) && isset($time[1]) && isset($time[2])) { + $timestamp = format_date($date, 'd F Y'); + } elseif (isset($time[0]) && isset($time[1])) { + $timestamp = format_date($date, 'F Y'); + } else { + $timestamp = $req; + } + + $data = new stdClass; + $data->title = $timestamp; + $data->url = site_url() . 'archive/' . $req; + $data->body = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title(); + + // Show an RSS feed + echo generate_rss($posts, $data); +}); + // Show the search page get('/search/:keyword', function ($keyword) { @@ -2231,7 +2326,7 @@ get('/search/:keyword', function ($keyword) { $tsearch->title = $keyword; $tsearch->url = site_url() . 'search/' . strtolower($keyword); $tsearch->count = $total; - $tsearch->description = i18n('Search_results_for') . ' ' . tag_i18n($keyword) . ' ' . i18n('by') . ' ' . blog_title() . '.'; + $tsearch->description = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title(); $vroot = rtrim(config('views.root'), '/'); @@ -2264,19 +2359,35 @@ get('/search/:keyword', function ($keyword) { } render($pview, array( - 'title' => i18n('Search_results_for') . ' ' . tag_i18n($keyword) . ' - ' . blog_title(), - 'description' => i18n('Search_results_for') . ' ' . tag_i18n($keyword) . ' ' . i18n('by') . ' ' . blog_title() . '.', + 'title' => i18n('Search_results_for') . ' ' . $keyword . ' - ' . blog_title(), + 'description' => i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title(), 'canonical' => site_url() . 'search/' . strtolower($keyword), 'page' => $page, 'posts' => $posts, 'search' => $tsearch, 'bodyclass' => 'in-search search-' . strtolower($keyword), - 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . i18n('Search_results_for') . ' ' . tag_i18n($keyword), + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . i18n('Search_results_for') . ' ' . $keyword, 'pagination' => has_pagination($total, $perpage, $page), 'is_search' => true, ), $layout); }); +// Show the RSS feed +get('/search/:keyword/feed', function ($keyword) { + + header('Content-Type: application/rss+xml'); + + $posts = get_keyword($keyword, 1, config('rss.count')); + + $data = new stdClass; + $data->title = $keyword; + $data->url = site_url() . 'search/' . strtolower($keyword); + $data->body = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title(); + + // Show an RSS feed + echo generate_rss($posts, $data); +}); + // The JSON API get('/api/json', function () { diff --git a/system/includes/functions.php b/system/includes/functions.php index ed823b3..8df327f 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -623,92 +623,171 @@ function find_post($year, $month, $name) } } -// Find draft. -function find_draft($year, $month, $name) +// Return static page. +function find_page($static = null) { - $posts = get_draft_posts(); + $pages = get_static_pages(); + + $tmp = array(); - foreach ($posts as $index => $v) { - $arr = explode('_', $v['basename']); - if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { + if (!empty($pages)) { - // Use the get_posts method to return - // a properly parsed object + foreach ($pages as $index => $v) { + if (is_null($static)) { + $post = new stdClass; - $ar = get_posts($posts, $index + 1, 1); - $nx = get_posts($posts, $index, 1); - $pr = get_posts($posts, $index + 2, 1); + // The static page URL + $url= $v['filename']; + + $post->url = site_url() . $url; - if ($index == 0) { - if (isset($pr[0])) { + $post->file = $v['dirname'] . '/' . $v['basename']; + $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); + + $post->md = $url; + + // Get the contents and convert it to HTML + $content = file_get_contents($post->file); + + // Extract the title and body + $post->title = get_content_tag('t', $content, 'Untitled static page: ' . format_date($post->lastMod, 'l, j F Y, H:i')); + + // Get the contents and convert it to HTML + $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + + if (config('views.counter') == 'true') { + $post->views = get_views($post->file); + } + + $post->description = get_content_tag("d", $content, get_description($post->body)); + + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); + + $tmp[] = $post; + + } elseif (stripos($v['basename'], $static . '.md') !== false) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_pages($pages, $index + 1, 1); + $nx = get_pages($pages, $index, 1); + $pr = get_pages($pages, $index + 2, 1); + + if ($index == 0) { + if (isset($pr[0])) { + return array( + 'current' => $ar[0], + 'prev' => $pr[0] + ); + } else { + return array( + 'current' => $ar[0], + 'prev' => null + ); + } + } elseif (count($pages) == $index + 1) { return array( 'current' => $ar[0], - 'prev' => $pr[0] + 'next' => $nx[0] ); } else { return array( 'current' => $ar[0], - 'prev' => null + 'next' => $nx[0], + 'prev' => $pr[0] ); } - } elseif (count($posts) == $index + 1) { - return array( - 'current' => $ar[0], - 'next' => $nx[0] - ); - } else { - return array( - 'current' => $ar[0], - 'next' => $nx[0], - 'prev' => $pr[0] - ); } } } + + return $tmp; } -// Find scheduled post. -function find_scheduled($year, $month, $name) +// Return static subpage. +function find_subpage($static, $sub_static = null) { - $posts = get_scheduled_posts(); + $sub_pages = array_values(get_static_subpages($static)); - foreach ($posts as $index => $v) { - $arr = explode('_', $v['basename']); - if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { + $tmp = array(); - // Use the get_posts method to return - // a properly parsed object + if (!empty($sub_pages)) { - $ar = get_posts($posts, $index + 1, 1); - $nx = get_posts($posts, $index, 1); - $pr = get_posts($posts, $index + 2, 1); + foreach ($sub_pages as $index => $v) { + + if (is_null($sub_static)) { + + $post = new stdClass; - if ($index == 0) { - if (isset($pr[0])) { + // The static page URL + $url= $v['filename']; + $post->url = site_url() . $static . "/" . $url; + + $post->file = $v['dirname'] . '/' . $v['basename']; + $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); + + $post->md = $url; + + $post->parent = $static; + + // Get the contents and convert it to HTML + $content = file_get_contents($post->file); + + // Extract the title and body + $post->title = get_content_tag('t', $content, 'Untitled static subpage: ' . format_date($post->lastMod, 'l, j F Y, H:i')); + + // Get the contents and convert it to HTML + $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + + $post->views = get_views($post->file); + + $post->description = get_content_tag("d", $content, get_description($post->body)); + + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); + + $tmp[] = $post; + + } elseif (stripos($v['basename'], $sub_static . '.md') !== false) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_subpages($sub_pages, $index + 1, 1); + $nx = get_subpages($sub_pages, $index, 1); + $pr = get_subpages($sub_pages, $index + 2, 1); + + if ($index == 0) { + if (isset($pr[0])) { + return array( + 'current' => $ar[0], + 'prev' => $pr[0] + ); + } else { + return array( + 'current' => $ar[0], + 'prev' => null + ); + } + } elseif (count($sub_pages) == $index + 1) { return array( 'current' => $ar[0], - 'prev' => $pr[0] + 'next' => $nx[0] ); } else { return array( 'current' => $ar[0], - 'prev' => null + 'next' => $nx[0], + 'prev' => $pr[0] ); } - } elseif (count($posts) == $index + 1) { - return array( - 'current' => $ar[0], - 'next' => $nx[0] - ); - } else { - return array( - 'current' => $ar[0], - 'next' => $nx[0], - 'prev' => $pr[0] - ); } } } + + return $tmp; } // Return category page. @@ -969,54 +1048,6 @@ function get_profile_posts($name, $page, $perpage) return $tmp = get_posts($tmp, $page, $perpage); } -// Return draft list -function get_draft($profile, $page, $perpage) -{ - - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); - $posts = get_draft_posts(); - - $tmp = array(); - - foreach ($posts as $index => $v) { - $str = explode('/', $v['dirname']); - if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { - $tmp[] = $v; - } - } - - if (empty($tmp)) { - return false; - } - - return $tmp = get_posts($tmp, $page, $perpage); -} - -// Return scheduled list -function get_scheduled($profile, $page, $perpage) -{ - - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); - $posts = get_scheduled_posts(); - - $tmp = array(); - - foreach ($posts as $index => $v) { - $str = explode('/', $v['dirname']); - if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { - $tmp[] = $v; - } - } - - if (empty($tmp)) { - return false; - } - - return $tmp = get_posts($tmp, $page, $perpage); -} - // Return author info. function get_author($name) { @@ -1055,6 +1086,12 @@ function get_author($name) // Get the contents and convert it to HTML $author->about = MarkdownExtra::defaultTransform(remove_html_comments($content)); + + $author->body = $author->about; + + $author->title = $author->name; + + $author->description = $author->about; $tmp[] = $author; } @@ -1075,180 +1112,16 @@ function default_profile($name) $author = new stdClass; $author->name = $name; + $author->title = $name; $author->about = '
' . i18n('Author_Description') . '
'; - + $author->body = '' . i18n('Author_Description') . '
'; $author->description = i18n('Author_Description'); + $author->url = site_url(). 'author/' . $name; + $author->file = ''; return $tmp[] = $author; } -// Return static page. -function find_page($static = null) -{ - $pages = get_static_pages(); - - $tmp = array(); - - if (!empty($pages)) { - - foreach ($pages as $index => $v) { - if (is_null($static)) { - $post = new stdClass; - - // The static page URL - $url= $v['filename']; - - $post->url = site_url() . $url; - - $post->file = $v['dirname'] . '/' . $v['basename']; - $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - - $post->md = $url; - - // Get the contents and convert it to HTML - $content = file_get_contents($post->file); - - // Extract the title and body - $post->title = get_content_tag('t', $content, 'Untitled static page: ' . format_date($post->lastMod, 'l, j F Y, H:i')); - - // Get the contents and convert it to HTML - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); - - if (config('views.counter') == 'true') { - $post->views = get_views($post->file); - } - - $post->description = get_content_tag("d", $content, get_description($post->body)); - - $word_count = str_word_count(strip_tags($post->body)); - $post->readTime = ceil($word_count / 200); - - $tmp[] = $post; - - } elseif (stripos($v['basename'], $static . '.md') !== false) { - - // Use the get_posts method to return - // a properly parsed object - - $ar = get_pages($pages, $index + 1, 1); - $nx = get_pages($pages, $index, 1); - $pr = get_pages($pages, $index + 2, 1); - - if ($index == 0) { - if (isset($pr[0])) { - return array( - 'current' => $ar[0], - 'prev' => $pr[0] - ); - } else { - return array( - 'current' => $ar[0], - 'prev' => null - ); - } - } elseif (count($pages) == $index + 1) { - return array( - 'current' => $ar[0], - 'next' => $nx[0] - ); - } else { - return array( - 'current' => $ar[0], - 'next' => $nx[0], - 'prev' => $pr[0] - ); - } - } - } - } - - return $tmp; -} - -// Return static subpage. -function find_subpage($static, $sub_static = null) -{ - $sub_pages = array_values(get_static_subpages($static)); - - $tmp = array(); - - if (!empty($sub_pages)) { - - foreach ($sub_pages as $index => $v) { - - if (is_null($sub_static)) { - - $post = new stdClass; - - // The static page URL - $url= $v['filename']; - $post->url = site_url() . $static . "/" . $url; - - $post->file = $v['dirname'] . '/' . $v['basename']; - $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - - $post->md = $url; - - $post->parent = $static; - - // Get the contents and convert it to HTML - $content = file_get_contents($post->file); - - // Extract the title and body - $post->title = get_content_tag('t', $content, 'Untitled static subpage: ' . format_date($post->lastMod, 'l, j F Y, H:i')); - - // Get the contents and convert it to HTML - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); - - $post->views = get_views($post->file); - - $post->description = get_content_tag("d", $content, get_description($post->body)); - - $word_count = str_word_count(strip_tags($post->body)); - $post->readTime = ceil($word_count / 200); - - $tmp[] = $post; - - } elseif (stripos($v['basename'], $sub_static . '.md') !== false) { - - // Use the get_posts method to return - // a properly parsed object - - $ar = get_subpages($sub_pages, $index + 1, 1); - $nx = get_subpages($sub_pages, $index, 1); - $pr = get_subpages($sub_pages, $index + 2, 1); - - if ($index == 0) { - if (isset($pr[0])) { - return array( - 'current' => $ar[0], - 'prev' => $pr[0] - ); - } else { - return array( - 'current' => $ar[0], - 'prev' => null - ); - } - } elseif (count($sub_pages) == $index + 1) { - return array( - 'current' => $ar[0], - 'next' => $nx[0] - ); - } else { - return array( - 'current' => $ar[0], - 'next' => $nx[0], - 'prev' => $pr[0] - ); - } - } - } - } - - return $tmp; -} - // Return frontpage content function get_frontpage() { @@ -2678,18 +2551,26 @@ function not_found() } // Turn an array of posts into an RSS feed -function generate_rss($posts) +function generate_rss($posts, $data = null) { $feed = new Feed(); $channel = new Channel(); $rssLength = config('rss.char'); - + $data = $data; + + if (is_null($data)) { $channel ->title(blog_title()) ->description(blog_description()) ->url(site_url()) ->appendTo($feed); - + } else { + $channel + ->title($data->title) + ->description(strip_tags($data->body)) + ->url($data->url) + ->appendTo($feed); + } foreach ($posts as $p) { if (!empty($rssLength)) { @@ -2717,7 +2598,7 @@ function generate_rss($posts) ->appendTo($channel); } - echo $feed; + return $feed; } // Return post, archive url for sitemap diff --git a/system/vendor/suin/php-rss-writer/src/Suin/RSSWriter/SimpleXMLElement.php b/system/vendor/suin/php-rss-writer/src/Suin/RSSWriter/SimpleXMLElement.php index 1562993..c734719 100644 --- a/system/vendor/suin/php-rss-writer/src/Suin/RSSWriter/SimpleXMLElement.php +++ b/system/vendor/suin/php-rss-writer/src/Suin/RSSWriter/SimpleXMLElement.php @@ -8,6 +8,7 @@ namespace Suin\RSSWriter; */ class SimpleXMLElement extends \SimpleXMLElement { + #[\ReturnTypeWillChange] public function addChild($name, $value = null, $namespace = null) { if ($value !== null and is_string($value) === true) {