diff options
| author | dev | 2026-06-27 05:34:00 +0200 |
|---|---|---|
| committer | dev | 2026-06-27 05:34:00 +0200 |
| commit | b608ced142cd0527906b554e04376292f718f084 (patch) | |
| tree | 6f6937b35b902db3f0bca6476000dd61e3fcc85d /ssh/app/Http/Controllers | |
| parent | 0fe83c7f76b2fd6ce79541a71cdde5ec0b12becf (diff) | |
| parent | 043dd3ed90cac67975996bd881a997f38679bacd (diff) | |
| download | curious-b608ced142cd0527906b554e04376292f718f084.tar.gz | |
Merged cinema into mostdiscussed.com
Diffstat (limited to 'ssh/app/Http/Controllers')
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/ConfirmPasswordController.php | 40 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/ForgotPasswordController.php | 22 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/LoginController.php | 40 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/RegisterController.php | 73 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/ResetPasswordController.php | 30 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Auth/VerificationController.php | 42 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/CinemaController.php | 233 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/Controller.php | 13 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/FeedController.php | 97 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/HomeController.php | 28 | ||||
| -rw-r--r-- | ssh/app/Http/Controllers/IndexController.php | 150 |
11 files changed, 768 insertions, 0 deletions
diff --git a/ssh/app/Http/Controllers/Auth/ConfirmPasswordController.php b/ssh/app/Http/Controllers/Auth/ConfirmPasswordController.php new file mode 100644 index 0000000..138c1f0 --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -0,0 +1,40 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; +use Illuminate\Foundation\Auth\ConfirmsPasswords; + +class ConfirmPasswordController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Confirm Password Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling password confirmations and + | uses a simple trait to include the behavior. You're free to explore + | this trait and override any functions that require customization. + | + */ + + use ConfirmsPasswords; + + /** + * Where to redirect users when the intended url fails. + * + * @var string + */ + protected $redirectTo = RouteServiceProvider::HOME; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('auth'); + } +} diff --git a/ssh/app/Http/Controllers/Auth/ForgotPasswordController.php b/ssh/app/Http/Controllers/Auth/ForgotPasswordController.php new file mode 100644 index 0000000..465c39c --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -0,0 +1,22 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use Illuminate\Foundation\Auth\SendsPasswordResetEmails; + +class ForgotPasswordController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Password Reset Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling password reset emails and + | includes a trait which assists in sending these notifications from + | your application to your users. Feel free to explore this trait. + | + */ + + use SendsPasswordResetEmails; +} diff --git a/ssh/app/Http/Controllers/Auth/LoginController.php b/ssh/app/Http/Controllers/Auth/LoginController.php new file mode 100644 index 0000000..18a0d08 --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/LoginController.php @@ -0,0 +1,40 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; +use Illuminate\Foundation\Auth\AuthenticatesUsers; + +class LoginController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Login Controller + |-------------------------------------------------------------------------- + | + | This controller handles authenticating users for the application and + | redirecting them to your home screen. The controller uses a trait + | to conveniently provide its functionality to your applications. + | + */ + + use AuthenticatesUsers; + + /** + * Where to redirect users after login. + * + * @var string + */ + protected $redirectTo = RouteServiceProvider::HOME; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest')->except('logout'); + } +} diff --git a/ssh/app/Http/Controllers/Auth/RegisterController.php b/ssh/app/Http/Controllers/Auth/RegisterController.php new file mode 100644 index 0000000..c6a6de6 --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/RegisterController.php @@ -0,0 +1,73 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; +use App\User; +use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Validator; + +class RegisterController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Register Controller + |-------------------------------------------------------------------------- + | + | This controller handles the registration of new users as well as their + | validation and creation. By default this controller uses a trait to + | provide this functionality without requiring any additional code. + | + */ + + use RegistersUsers; + + /** + * Where to redirect users after registration. + * + * @var string + */ + protected $redirectTo = RouteServiceProvider::HOME; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest'); + } + + /** + * Get a validator for an incoming registration request. + * + * @param array $data + * @return \Illuminate\Contracts\Validation\Validator + */ + protected function validator(array $data) + { + return Validator::make($data, [ + 'name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'password' => ['required', 'string', 'min:8', 'confirmed'], + ]); + } + + /** + * Create a new user instance after a valid registration. + * + * @param array $data + * @return \App\User + */ + protected function create(array $data) + { + return User::create([ + 'name' => $data['name'], + 'email' => $data['email'], + 'password' => Hash::make($data['password']), + ]); + } +} diff --git a/ssh/app/Http/Controllers/Auth/ResetPasswordController.php b/ssh/app/Http/Controllers/Auth/ResetPasswordController.php new file mode 100644 index 0000000..b1726a3 --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/ResetPasswordController.php @@ -0,0 +1,30 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; +use Illuminate\Foundation\Auth\ResetsPasswords; + +class ResetPasswordController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Password Reset Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling password reset requests + | and uses a simple trait to include this behavior. You're free to + | explore this trait and override any methods you wish to tweak. + | + */ + + use ResetsPasswords; + + /** + * Where to redirect users after resetting their password. + * + * @var string + */ + protected $redirectTo = RouteServiceProvider::HOME; +} diff --git a/ssh/app/Http/Controllers/Auth/VerificationController.php b/ssh/app/Http/Controllers/Auth/VerificationController.php new file mode 100644 index 0000000..5e749af --- /dev/null +++ b/ssh/app/Http/Controllers/Auth/VerificationController.php @@ -0,0 +1,42 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; +use Illuminate\Foundation\Auth\VerifiesEmails; + +class VerificationController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Email Verification Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling email verification for any + | user that recently registered with the application. Emails may also + | be re-sent if the user didn't receive the original email message. + | + */ + + use VerifiesEmails; + + /** + * Where to redirect users after verification. + * + * @var string + */ + protected $redirectTo = RouteServiceProvider::HOME; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('auth'); + $this->middleware('signed')->only('verify'); + $this->middleware('throttle:6,1')->only('verify', 'resend'); + } +} diff --git a/ssh/app/Http/Controllers/CinemaController.php b/ssh/app/Http/Controllers/CinemaController.php new file mode 100644 index 0000000..75c93aa --- /dev/null +++ b/ssh/app/Http/Controllers/CinemaController.php @@ -0,0 +1,233 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Support\Facades\DB; +use Illuminate\Http\Request; + +class CinemaController extends Controller +{ + public function cinema(Request $request) + { + $order = $request->input('order', 'ref_count'); + $direction = $request->input('direction', 'desc'); + $validOrders = ['ref_count', 'score', 'num_votes', 'num_accolades', 'start_year']; + $validDirections = ['asc', 'desc']; + if (! in_array($order, $validOrders)) { + $order = 'ref_count'; + } + if (! in_array($direction, $validDirections)) { + $direction = 'desc'; + } + + $refCounts = DB::connection('cinema') + ->table('links') + ->select('links.param', DB::raw('COUNT(*) as ref_count')) + ->where('links.host', 'www.imdb.com') + ->where('links.field', 1) + ->groupBy('links.param'); + + $movies = DB::connection('cinema') + ->table('imdb') + ->select( + 'imdb.id', + 'imdb.imdb_id', + 'imdb.primary_title', + 'imdb.original_title', + 'imdb.start_year', + 'imdb.average_rating', + 'imdb.num_votes', + 'imdb.synopsis', + 'imdb.poster_url', + 'imdb.title_type', + 'imdb.runtime_minutes', + 'imdb.has_people', + 'imdb.average_rating as score', + 'imdb.num_accolades', + DB::raw('COALESCE(ref.ref_count, 0) as ref_count') + ) + ->leftJoinSub($refCounts, 'ref', function ($join) { + $join->on('ref.param', '=', 'imdb.imdb_id'); + }) + ->whereNotNull('imdb.primary_title') + ->whereNotNull('imdb.wiki_article') + ->where('imdb.title_type', 'movie') + ->orderBy($order, $direction) + ->simplePaginate(12); + + $total = DB::connection('cinema') + ->table('imdb') + ->whereNotNull('primary_title') + ->whereNotNull('wiki_article') + ->where('title_type', 'movie') + ->count(); + + return view('cinema', ['movies' => $movies, 'count' => $total, 'order' => $order, 'direction' => $direction]); + } + + public function show($id) + { + $movie = DB::connection('cinema') + ->table('imdb') + ->where('imdb.imdb_id', $id) + ->first(); + + if (! $movie) { + abort(404); + } + + $genres = DB::connection('cinema') + ->table('imdb_genre') + ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id') + ->where('imdb_genre.imdb_id', $movie->id) + ->pluck('genre.name'); + + $casts = DB::connection('cinema') + ->table('who') + ->join('people', 'people.id', '=', 'who.people_id') + ->join('profession', 'profession.id', '=', 'who.profession_id') + ->where('who.imdb_id', $movie->id) + ->select('people.name', 'profession.name as profession') + ->get(); + + $actors = $casts->where('profession', 'actor')->take(8); + $directors = $casts->where('profession', 'director'); + $screenwriters = $casts->where('profession', 'screenwriter')->take(3); + + $hnStories = DB::connection('cinema') + ->table('links') + ->join('story', 'story.id', '=', 'links.story_id') + ->select( + 'story.story_id', + 'story.title', + 'story.type', + 'story.text', + 'story.score', + 'story.descendants', + 'story.time' + ) + ->where('links.host', 'www.imdb.com') + ->where('links.field', 1) + ->where('links.param', $id) + ->orderBy('story.time', 'desc') + ->get(); + + return view('cinema_show', [ + 'movie' => $movie, + 'genres' => $genres, + 'actors' => $actors, + 'directors' => $directors, + 'screenwriters' => $screenwriters, + 'hnStories' => $hnStories, + ]); + } + + public function genres() + { + $genres = DB::connection('cinema') + ->table('genre') + ->select('genre.name', DB::raw('COUNT(imdb_genre.imdb_id) as count')) + ->join('imdb_genre', 'imdb_genre.genre_id', '=', 'genre.id') + ->join('imdb', 'imdb.id', '=', 'imdb_genre.imdb_id') + ->whereNotNull('imdb.primary_title') + ->whereNotNull('imdb.wiki_article') + ->where('imdb.title_type', 'movie') + ->groupBy('genre.name') + ->orderBy('count', 'desc') + ->get(); + + return view('genres', ['genres' => $genres]); + } + + public function genre($name) + { + $genre = DB::connection('cinema') + ->table('genre') + ->where('name', $name) + ->first(); + + if (! $genre) { + abort(404); + } + + $movies = DB::connection('cinema') + ->table('imdb') + ->select( + 'imdb.id', + 'imdb.imdb_id', + 'imdb.primary_title', + 'imdb.original_title', + 'imdb.start_year', + 'imdb.average_rating', + 'imdb.num_votes', + 'imdb.synopsis', + 'imdb.poster_url', + 'imdb.title_type', + 'imdb.runtime_minutes' + ) + ->join('imdb_genre', 'imdb_genre.imdb_id', '=', 'imdb.id') + ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id') + ->where('genre.name', $name) + ->whereNotNull('imdb.primary_title') + ->whereNotNull('imdb.wiki_article') + ->where('imdb.title_type', 'movie') + ->orderBy('imdb.average_rating', 'desc') + ->simplePaginate(12); + + $count = DB::connection('cinema') + ->table('imdb') + ->join('imdb_genre', 'imdb_genre.imdb_id', '=', 'imdb.id') + ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id') + ->where('genre.name', $name) + ->whereNotNull('imdb.primary_title') + ->whereNotNull('imdb.wiki_article') + ->where('imdb.title_type', 'movie') + ->count(); + + return view('genre_movies', ['movies' => $movies, 'count' => $count, 'genre_name' => $name]); + } + + public function search(Request $request) + { + $query = $request->input('q', ''); + + $movies = DB::connection('cinema') + ->table('imdb') + ->select( + 'imdb.id', + 'imdb.imdb_id', + 'imdb.primary_title', + 'imdb.original_title', + 'imdb.start_year', + 'imdb.average_rating', + 'imdb.num_votes', + 'imdb.synopsis', + 'imdb.poster_url', + 'imdb.title_type', + 'imdb.runtime_minutes' + ) + ->whereNotNull('imdb.primary_title') + ->whereNotNull('imdb.wiki_article') + ->where('imdb.title_type', 'movie') + ->where(function ($q) use ($query) { + $q->where('imdb.primary_title', 'like', '%' . $query . '%') + ->orWhere('imdb.original_title', 'like', '%' . $query . '%') + ->orWhere('imdb.synopsis', 'like', '%' . $query . '%'); + }) + ->simplePaginate(12); + + $total = DB::connection('cinema') + ->table('imdb') + ->whereNotNull('primary_title') + ->whereNotNull('wiki_article') + ->where('title_type', 'movie') + ->where(function ($q) use ($query) { + $q->where('primary_title', 'like', '%' . $query . '%') + ->orWhere('original_title', 'like', '%' . $query . '%') + ->orWhere('synopsis', 'like', '%' . $query . '%'); + }) + ->count(); + + return view('cinema', ['movies' => $movies, 'count' => $total, 'search_query' => $query]); + } +} diff --git a/ssh/app/Http/Controllers/Controller.php b/ssh/app/Http/Controllers/Controller.php new file mode 100644 index 0000000..a0a2a8a --- /dev/null +++ b/ssh/app/Http/Controllers/Controller.php @@ -0,0 +1,13 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Foundation\Bus\DispatchesJobs; +use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Routing\Controller as BaseController; + +class Controller extends BaseController +{ + use AuthorizesRequests, DispatchesJobs, ValidatesRequests; +} diff --git a/ssh/app/Http/Controllers/FeedController.php b/ssh/app/Http/Controllers/FeedController.php new file mode 100644 index 0000000..9d20fce --- /dev/null +++ b/ssh/app/Http/Controllers/FeedController.php @@ -0,0 +1,97 @@ +<?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 FeedController extends Controller +{ + + public function new() + { + // creating rss feed with our most recent 20 posts + $articles = Article::join('discussion', 'discussion.article_id', '=', 'view_article.id') + ->select('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->groupBy('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->where('view_article.created_at', '<', now()->subMinutes(30)) + ->orderByRaw('MAX(discussion.posted_on) DESC') + ->take(20) + ->get(); + + return Helper::makeFeed($articles, "new"); + } + + public function mastodon() + { + $articles = Article::join('discussion', 'discussion.article_id', '=', 'view_article.id') + ->select('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->groupBy('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->where('view_article.created_at', '<', now()->subMinutes(30)) + ->orderByRaw('MAX(discussion.posted_on) DESC') + ->take(20) + ->get(); + return Helper::makeFeed($articles, "mastodon"); + } + public function mastodon_test() + { + $articles = Article::join('discussion', 'discussion.article_id', '=', 'view_article.id') + ->select('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->groupBy('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->where('view_article.created_at', '<', now()->subMinutes(30)) + ->orderByRaw('MAX(discussion.posted_on) DESC') + ->take(20) + ->get(); + return Helper::makeFeed($articles, "mastodon_test"); + } + + 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")); + } +} diff --git a/ssh/app/Http/Controllers/HomeController.php b/ssh/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..7cbc2c3 --- /dev/null +++ b/ssh/app/Http/Controllers/HomeController.php @@ -0,0 +1,28 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; + +class HomeController extends Controller +{ + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Contracts\Support\Renderable + */ + public function index() + { + return view('home'); + } +} diff --git a/ssh/app/Http/Controllers/IndexController.php b/ssh/app/Http/Controllers/IndexController.php new file mode 100644 index 0000000..7e7b31b --- /dev/null +++ b/ssh/app/Http/Controllers/IndexController.php @@ -0,0 +1,150 @@ +<?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 about() + { + $count_articles = DB::Select("SELECT COUNT(*) as count FROM article;")[0]; + $count_discussions = DB::Select("SELECT COUNT(*) as count FROM discussion;")[0]; + $count_comments = DB::Select("SELECT sum(comments) as count FROM discussion;")[0]; + $count_upvotes = DB::Select("SELECT sum(upvotes) as count FROM discussion;")[0]; + return view('about', [ + "count_articles" => $count_articles->count, + "count_discussions" => $count_discussions->count, + "count_comments" => number_format($count_comments->count), + "count_upvotes" => number_format($count_upvotes->count)]); + } + + 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(); + $articles = $articles->orderBy('impact', 'desc'); + $count = $articles->count(); + $articles = $articles->simplePaginate(10); + + return view('list', ["articles" => $articles, "count" => $count]); + } + + public function new() + { + $articles = Article::join('discussion', 'discussion.article_id', '=', 'view_article.id') + ->select('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->groupBy('view_article.id', 'view_article.article_id', 'view_article.url', 'view_article.title', 'view_article.excerpt_html', 'view_article.impact', 'view_article.upvotes', 'view_article.comments', 'view_article.repost') + ->orderByRaw('MAX(discussion.posted_on) DESC'); + + $count = $articles->count(); + $articles = $articles->simplePaginate(10); + + return view('list', ["articles" => $articles, "count" => $count]); + } + + public function show( $id ) { + $articles = Article::where('id', $id); + $articles = $articles->simplePaginate(10); + $page_title = ""; + foreach($articles as $a) { + $page_title = $a->title; + } + return view('list', ["articles" => $articles, "count" => 1, "page_title" => $page_title]); + } + + 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('excerpt_html', 'like', $q); + }); + } + $count = $articles->count(); + + if ( "on" == $request->input("onlypopular") ) { + $articles = $articles->orderBy('impact', 'desc'); + } + $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'); + $letters = DB::select("SELECT DISTINCT LEFT(name, 1) as name FROM category ORDER BY left(name, 1);"); + + return view('topicindex', ['topics' => $categories, 'letters' => $letters]); + } + + public function random() { + $articles = new Article; + $articles = $articles->inRandomOrder(); + $count = $articles->count(); + $articles = $articles->simplePaginate(10); + + return view('list', ["articles" => $articles, "count" => $count]); + } + + public function populartopics() { + $topics = DB::select(" + SELECT + c.name, + count(c.name) AS count + FROM category AS c + JOIN + article_category AS ac ON c.id = ac.category_id + GROUP BY + c.name + ORDER BY count(c.name) DESC;"); +#echo "<pre>"; var_dump($topics);exit; + + return view('topicpopular', ['topics' => $topics ]); + } +} |
