diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 5625fe96..82865cca 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -125,6 +125,7 @@ class Controller $router->any('/yt2', 'AcquisitionActions::executeYT2'); $router->get('/verify/{token}', 'AcquisitionActions::executeVerify'); + $router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter'); $router->post('/set-culture', 'i18nActions::setCulture'); diff --git a/controller/action/ContentActions.class.php b/controller/action/ContentActions.class.php index 3a1b3395..4dd6463c 100644 --- a/controller/action/ContentActions.class.php +++ b/controller/action/ContentActions.class.php @@ -364,4 +364,25 @@ class ContentActions extends Actions 'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count) ]; } + public static function executePostCategoryFilter(string $category) + { + Response::enableHttpCache(); + + $filter_post = []; + + $posts = array_filter( + Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), + function(Post $post) use ($category) { + return (($post->getCategory() === $category) && (!$post->getDate() || $post->getDate()->format('U') <= date('U'))); + }); + + + + return ['content/news', [ + 'posts' => $posts, + View::LAYOUT_PARAMS => [ + 'showRssLink' => true + ] + ]]; + } }