aboutsummaryrefslogtreecommitdiffstats
path: root/core/include
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2022-03-14 11:32:08 +0100
committerThomas Lange <code@nerdmind.de>2022-03-14 11:32:08 +0100
commitb22c33b97305d3c264f32b1fe357886aa149e19f (patch)
tree838a3f2e03308a77551adb49bb1ec4d662a6e505 /core/include
parent4b0b1c405c5dd242fdef37930502dd4341222c3d (diff)
downloadblog-b22c33b97305d3c264f32b1fe357886aa149e19f.tar.gz
blog-b22c33b97305d3c264f32b1fe357886aa149e19f.tar.xz
blog-b22c33b97305d3c264f32b1fe357886aa149e19f.zip
Include category data in feed item template
Include the category data and the category tree data in the feed item template in the same way as on the post's "main" or "item" template. So in the feed item template, the available parameters are now: $POST (already existed before) $USER (already existed before) $CATEGORY (added with this commit) $CATEGORIES (added with this commit) See the template documentation in the wiki for more information.
Diffstat (limited to 'core/include')
-rw-r--r--core/include/feed/main.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/include/feed/main.php b/core/include/feed/main.php
index 9f1e4d4..2e05518 100644
--- a/core/include/feed/main.php
+++ b/core/include/feed/main.php
@@ -7,6 +7,7 @@ HTTP::responseHeader(HTTP::HEADER_CONTENT_TYPE, HTTP::CONTENT_TYPE_XML);
#===============================================================================
# Get repositories
#===============================================================================
+$CategoryRepository = Application::getRepository('Category');
$PostRepository = Application::getRepository('Post');
$UserRepository = Application::getRepository('User');
@@ -34,8 +35,24 @@ foreach($posts as $Post) {
$post_data = generateItemTemplateData($Post);
$post_data['GUID'] = sha1($Post->getID().$Post->get('time_insert'));
+ #===============================================================================
+ # Generate category template data (including parents)
+ #===============================================================================
+ foreach($CategoryRepository->findWithParents($Post->get('category')) as $Category) {
+ $category_list[] = generateItemTemplateData($Category);
+ }
+
+ #===============================================================================
+ # Define data variable for current category
+ #===============================================================================
+ if(isset($category_list)) {
+ $category_data = $category_list[array_key_last($category_list)];
+ }
+
$ItemTemplate->set('POST', $post_data);
$ItemTemplate->set('USER', generateItemTemplateData($User));
+ $ItemTemplate->set('CATEGORY', $category_data ?? []);
+ $ItemTemplate->set('CATEGORIES', $category_list ?? []);
$templates[] = $ItemTemplate;
}