From 3afd5b2fd1f217f12ecad465449524fe93cacf09 Mon Sep 17 00:00:00 2001 From: horus Date: Sat, 11 Apr 2020 19:44:37 +0200 Subject: Adds RSS- and Atom-Feeds. --- app/Http/Controllers/FeedController.php | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/Http/Controllers/FeedController.php (limited to 'app/Http/Controllers/FeedController.php') diff --git a/app/Http/Controllers/FeedController.php b/app/Http/Controllers/FeedController.php new file mode 100644 index 0000000..9fd73a5 --- /dev/null +++ b/app/Http/Controllers/FeedController.php @@ -0,0 +1,67 @@ +take(20)->get(); + return Helper::makeFeed($articles, "new"); + } + + public function popular() + { + + $articles = new Article; + $articles = $articles->setTable('view_popular'); + $articles = $articles->take(20)->get(); + return Helper::makeFeed($articles, "popular"); + } + + public function search(Request $request) { + $search_unsafe = $request->input("q"); + + if ( "" == $search_unsafe ) { + $search_unsafe = ""; + } + + $search_unsafe = explode(",", $request->input("q")); + + $articles = new Article; + + if ( "on" == $request->input("onlypopular") ) { + $articles = $articles->setTable('view_popular'); + } + + foreach($search_unsafe as $q) { + $q = Helper::escapeLike($q); + $q = "%".$q."%"; + $articles = $articles->where(function ($query) use ($q) { + $query->whereHas('getCategories', function ($query) use ($q){ + $query->where('name', 'like', $q); + }) + ->orWhere('title', 'like', $q) + ->orWhere('url', 'like', $q) + ->orWhere('excerpt_html', 'like', $q); + }); + } + $count = $articles->count(); + + if ( "on" == $request->input("onlypopular") ) { + $articles = $articles->orderBy('impact', 'desc'); + } + $articles = $articles->orderBy('created_at', 'desc'); + + return Helper::makeFeed($articles->take(20)->get(), $request->input("q")); + } +} -- cgit v1.2.3