From b22c33b97305d3c264f32b1fe357886aa149e19f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 14 Mar 2022 11:32:08 +0100 Subject: 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. --- core/include/feed/main.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core/include/feed') 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; } -- cgit v1.2.3