summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/IndexController.php
diff options
context:
space:
mode:
authorhorus2020-04-02 21:52:04 +0200
committerhorus2020-04-02 21:52:04 +0200
commit5a8c47e29afdbb61c32c1e03162abb1bb871ee9e (patch)
tree19cd2e0c48119a703306a71df813d07666289e8f /app/Http/Controllers/IndexController.php
downloadcurious-5a8c47e29afdbb61c32c1e03162abb1bb871ee9e.tar.gz
Initial commit.
Diffstat (limited to 'app/Http/Controllers/IndexController.php')
-rw-r--r--app/Http/Controllers/IndexController.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php
new file mode 100644
index 0000000..7ae362a
--- /dev/null
+++ b/app/Http/Controllers/IndexController.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use App\Article;
+use App\Discussion;
+use App\Category;
+use App\Libraries\Helper;
+
+class IndexController extends Controller
+{
+
+ public function index()
+ {
+ return view('index');
+ }
+
+ public function topic( $topic )
+ {
+ $articles = new Category;
+ $articles = $articles->orWhere('name', $topic);
+ $articles = $articles->get()->first();
+ if ( is_null($articles) ) {
+ abort(404);
+ }
+ $articles = $articles->getArticles();
+ $count = $articles->count();
+ $articles = $articles->simplePaginate(10);
+
+ return view('list', ["articles" => $articles, "count" => $count]);
+ }
+
+ public function new()
+ {
+ $articles = Article::orderBy('created_at', 'desc');
+ $count = $articles->count();
+ $articles = $articles->simplePaginate(10);
+
+ return view('list', ["articles" => $articles, "count" => $count]);
+ }
+
+ 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();
+ $articles = $articles->orderBy('created_at', 'desc');
+ $articles = $articles->simplePaginate(10);
+
+ return view('list', ["articles" => $articles, "count" => $count]);
+ }
+
+ public function popular()
+ {
+ $articles = new Article;
+ $articles = $articles->setTable('view_popular');
+ $count = $articles->count();
+ $articles = $articles->simplePaginate(10);
+
+ return view('list', ["articles" => $articles, "count" => $count]);
+ }
+
+ function topicindex() {
+ $categories = Category::orderBy('name');
+
+ return view('topicindex', ['topics' => $categories]);
+ }
+
+ public function random() {
+ $articles = new Article;
+ $articles = $articles->inRandomOrder();
+ $count = $articles->count();
+ $articles = $articles->simplePaginate(10);
+
+ return view('list', ["articles" => $articles, "count" => $count]);
+ }
+}