81 lines
3.0 KiB
PHP
81 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\ArtworkService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
protected ArtworkService $artworks;
|
|
|
|
public function __construct(ArtworkService $artworks)
|
|
{
|
|
$this->artworks = $artworks;
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$page_title = 'Skinbase - Photography, Skins & Wallpapers';
|
|
$page_meta_description = 'Skinbase legacy home, rendered via Laravel.';
|
|
$page_meta_keywords = 'wallpapers, skins, photography, community';
|
|
|
|
$featuredResult = $this->artworks->getFeaturedArtworks(null, 39);
|
|
if ($featuredResult instanceof \Illuminate\Pagination\LengthAwarePaginator) {
|
|
$featured = $featuredResult->getCollection()->first();
|
|
} elseif (is_array($featuredResult)) {
|
|
$featured = $featuredResult[0] ?? null;
|
|
} else {
|
|
$featured = method_exists($featuredResult, 'first') ? $featuredResult->first() : $featuredResult;
|
|
}
|
|
|
|
$memberFeatured = $featured;
|
|
|
|
$latestUploads = $this->artworks->getLatestArtworks(20);
|
|
|
|
// Forum news (root forum section id 2876)
|
|
$forumNews = DB::table('forum_topics as t1')
|
|
->leftJoin('users as u', 't1.user_id', '=', 'u.user_id')
|
|
->select('t1.topic_id', 't1.topic', 'u.uname', 't1.post_date', 't1.preview')
|
|
->where('t1.root_id', 2876)
|
|
->where('t1.privilege', '<', 4)
|
|
->orderBy('t1.post_date', 'desc')
|
|
->limit(8)
|
|
->get();
|
|
|
|
// Our news (latest site news)
|
|
$ourNews = DB::table('news as t1')
|
|
->join('news_categories as c', 't1.category_id', '=', 'c.category_id')
|
|
->join('users as u', 't1.user_id', '=', 'u.user_id')
|
|
->selectRaw('t1.news_id, t1.headline, t1.user_id, t1.picture, t1.preview, u.uname, t1.create_date, t1.views, c.category_name, (SELECT COUNT(*) FROM news_comments WHERE news_id = t1.news_id) AS num_comments')
|
|
->orderBy('t1.create_date', 'desc')
|
|
->limit(5)
|
|
->get();
|
|
|
|
// Latest forum activity (exclude rootless and news root)
|
|
$latestForumActivity = DB::table('forum_topics as t1')
|
|
->selectRaw('t1.topic_id, t1.topic, (SELECT COUNT(*) FROM forum_posts WHERE topic_id = t1.topic_id) AS numPosts')
|
|
->where('t1.root_id', '<>', 0)
|
|
->where('t1.root_id', '<>', 2876)
|
|
->where('t1.privilege', '<', 4)
|
|
->orderBy('t1.last_update', 'desc')
|
|
->orderBy('t1.post_date', 'desc')
|
|
->limit(10)
|
|
->get();
|
|
|
|
return view('web.home', compact(
|
|
'page_title',
|
|
'page_meta_description',
|
|
'page_meta_keywords',
|
|
'featured',
|
|
'memberFeatured',
|
|
'latestUploads',
|
|
'forumNews',
|
|
'ourNews',
|
|
'latestForumActivity'
|
|
));
|
|
}
|
|
}
|