feat: increase gallery grid from 4 to 5 columns per row on desktopfeat: increase gallery grid from 4 to 5 columns per row on desktop

This commit is contained in:
2026-02-25 19:11:23 +01:00
parent 5c97488e80
commit 0032aec02f
131 changed files with 15674 additions and 597 deletions

View File

@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Artwork;
use App\Models\ArtworkAward;
use App\Services\ArtworkAwardService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
final class ArtworkAwardController extends Controller
{
public function __construct(
private readonly ArtworkAwardService $service
) {}
/**
* POST /api/artworks/{id}/award
* Award the artwork with a medal.
*/
public function store(Request $request, int $id): JsonResponse
{
$user = $request->user();
$artwork = Artwork::findOrFail($id);
$this->authorize('award', [ArtworkAward::class, $artwork]);
$data = $request->validate([
'medal' => ['required', 'string', 'in:gold,silver,bronze'],
]);
$award = $this->service->award($artwork, $user, $data['medal']);
return response()->json(
$this->buildPayload($artwork->id, $user->id),
201
);
}
/**
* PUT /api/artworks/{id}/award
* Change an existing award medal.
*/
public function update(Request $request, int $id): JsonResponse
{
$user = $request->user();
$artwork = Artwork::findOrFail($id);
$existingAward = ArtworkAward::where('artwork_id', $artwork->id)
->where('user_id', $user->id)
->firstOrFail();
$this->authorize('change', $existingAward);
$data = $request->validate([
'medal' => ['required', 'string', 'in:gold,silver,bronze'],
]);
$award = $this->service->changeAward($artwork, $user, $data['medal']);
return response()->json($this->buildPayload($artwork->id, $user->id));
}
/**
* DELETE /api/artworks/{id}/award
* Remove the user's award for this artwork.
*/
public function destroy(Request $request, int $id): JsonResponse
{
$user = $request->user();
$artwork = Artwork::findOrFail($id);
$existingAward = ArtworkAward::where('artwork_id', $artwork->id)
->where('user_id', $user->id)
->firstOrFail();
$this->authorize('remove', $existingAward);
$this->service->removeAward($artwork, $user);
return response()->json($this->buildPayload($artwork->id, $user->id));
}
/**
* GET /api/artworks/{id}/awards
* Return award stats + viewer's current award.
*/
public function show(Request $request, int $id): JsonResponse
{
$artwork = Artwork::findOrFail($id);
return response()->json($this->buildPayload($artwork->id, $request->user()?->id));
}
// -------------------------------------------------------------------------
// All authorization is delegated to ArtworkAwardPolicy via $this->authorize().
private function buildPayload(int $artworkId, ?int $userId): array
{
$stat = \App\Models\ArtworkAwardStat::find($artworkId);
$userAward = $userId
? ArtworkAward::where('artwork_id', $artworkId)
->where('user_id', $userId)
->value('medal')
: null;
return [
'awards' => [
'gold' => $stat?->gold_count ?? 0,
'silver' => $stat?->silver_count ?? 0,
'bronze' => $stat?->bronze_count ?? 0,
'score' => $stat?->score_total ?? 0,
],
'viewer_award' => $userAward,
];
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\ArtworkResource;
use App\Models\Artwork;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Str;
class ArtworkNavigationController extends Controller
{
/**
* GET /api/artworks/navigation/{id}
*
* Returns prev/next published artworks by the same author.
*/
public function neighbors(int $id): JsonResponse
{
$artwork = Artwork::published()
->select(['id', 'user_id', 'title', 'slug'])
->find($id);
if (! $artwork) {
return response()->json([
'prev_id' => null, 'next_id' => null,
'prev_url' => null, 'next_url' => null,
'prev_slug' => null, 'next_slug' => null,
]);
}
$scope = Artwork::published()
->select(['id', 'title', 'slug'])
->where('user_id', $artwork->user_id);
$prev = (clone $scope)->where('id', '<', $id)->orderByDesc('id')->first();
$next = (clone $scope)->where('id', '>', $id)->orderBy('id')->first();
$prevSlug = $prev ? (Str::slug($prev->slug ?: $prev->title) ?: (string) $prev->id) : null;
$nextSlug = $next ? (Str::slug($next->slug ?: $next->title) ?: (string) $next->id) : null;
return response()->json([
'prev_id' => $prev?->id,
'next_id' => $next?->id,
'prev_url' => $prev ? url('/art/' . $prev->id . '/' . $prevSlug) : null,
'next_url' => $next ? url('/art/' . $next->id . '/' . $nextSlug) : null,
'prev_slug' => $prevSlug,
'next_slug' => $nextSlug,
]);
}
/**
* GET /api/artworks/{id}/page
*
* Returns full artwork resource by numeric ID for client-side (no-reload) navigation.
*/
public function pageData(int $id): JsonResponse
{
$artwork = Artwork::with(['user.profile', 'categories.contentType', 'tags', 'stats'])
->published()
->find($id);
if (! $artwork) {
return response()->json(['error' => 'Not found'], 404);
}
$resource = (new ArtworkResource($artwork))->toArray(request());
return response()->json($resource);
}
}

View File

@@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\Search;
use App\Http\Controllers\Controller;
use App\Http\Resources\ArtworkListResource;
use App\Models\Artwork;
use App\Models\Tag;
use App\Services\ArtworkSearchService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Artwork search endpoints powered by Meilisearch.
*
* GET /api/search/artworks?q=&tags[]=&category=&orientation=&sort=
* GET /api/search/artworks/tag/{slug}
* GET /api/search/artworks/category/{cat}
* GET /api/search/artworks/related/{id}
*/
class ArtworkSearchController extends Controller
{
public function __construct(
private readonly ArtworkSearchService $search
) {}
/**
* GET /api/search/artworks
*/
public function index(Request $request): JsonResponse
{
$validated = $request->validate([
'q' => ['nullable', 'string', 'max:200'],
'tags' => ['nullable', 'array', 'max:10'],
'tags.*' => ['string', 'max:80'],
'category' => ['nullable', 'string', 'max:80'],
'orientation' => ['nullable', 'in:landscape,portrait,square'],
'resolution' => ['nullable', 'string', 'max:20'],
'author_id' => ['nullable', 'integer', 'min:1'],
'sort' => ['nullable', 'string', 'regex:/^(created_at|downloads|likes|views):(asc|desc)$/'],
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
]);
$results = $this->search->search(
q: (string) ($validated['q'] ?? ''),
filters: array_filter([
'tags' => $validated['tags'] ?? [],
'category' => $validated['category'] ?? null,
'orientation' => $validated['orientation'] ?? null,
'resolution' => $validated['resolution'] ?? null,
'author_id' => $validated['author_id'] ?? null,
'sort' => $validated['sort'] ?? null,
]),
perPage: (int) ($validated['per_page'] ?? 24),
);
// Eager-load relations needed by ArtworkListResource
$results->getCollection()->loadMissing(['user', 'categories.contentType']);
return ArtworkListResource::collection($results)->response();
}
/**
* GET /api/search/artworks/tag/{slug}
*/
public function byTag(Request $request, string $slug): JsonResponse
{
$tag = Tag::where('slug', $slug)->first();
if (! $tag) {
return response()->json(['message' => 'Tag not found.'], 404);
}
$results = $this->search->byTag($slug, (int) $request->query('per_page', 24));
return response()->json([
'tag' => ['id' => $tag->id, 'name' => $tag->name, 'slug' => $tag->slug],
'results' => $results,
]);
}
/**
* GET /api/search/artworks/category/{cat}
*/
public function byCategory(Request $request, string $cat): JsonResponse
{
$results = $this->search->byCategory($cat, (int) $request->query('per_page', 24));
return response()->json($results);
}
/**
* GET /api/search/artworks/related/{id}
*/
public function related(int $id): JsonResponse
{
$artwork = Artwork::with(['tags'])->find($id);
if (! $artwork) {
return response()->json(['message' => 'Artwork not found.'], 404);
}
$results = $this->search->related($artwork, 12);
return response()->json($results);
}
}

View File

@@ -9,44 +9,49 @@ use App\Http\Requests\Tags\PopularTagsRequest;
use App\Http\Requests\Tags\TagSearchRequest;
use App\Models\Tag;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
final class TagController extends Controller
{
public function search(TagSearchRequest $request): JsonResponse
{
$q = (string) ($request->validated()['q'] ?? '');
$q = trim($q);
$q = trim((string) ($request->validated()['q'] ?? ''));
$query = Tag::query()->where('is_active', true);
if ($q !== '') {
$query->where(function ($sub) use ($q): void {
$sub->where('name', 'like', $q . '%')
->orWhere('slug', 'like', $q . '%');
});
}
// Short results cached for 2 min; empty-query (popular suggestions) for 5 min.
$ttl = $q === '' ? 300 : 120;
$cacheKey = 'tags.search.' . ($q === '' ? '__empty__' : md5($q));
$tags = $query
->orderByDesc('usage_count')
->limit(20)
->get(['id', 'name', 'slug', 'usage_count']);
$data = Cache::remember($cacheKey, $ttl, function () use ($q): mixed {
$query = Tag::query()->where('is_active', true);
if ($q !== '') {
$query->where(function ($sub) use ($q): void {
$sub->where('name', 'like', $q . '%')
->orWhere('slug', 'like', $q . '%');
});
}
return response()->json([
'data' => $tags,
]);
return $query
->orderByDesc('usage_count')
->limit(20)
->get(['id', 'name', 'slug', 'usage_count']);
});
return response()->json(['data' => $data]);
}
public function popular(PopularTagsRequest $request): JsonResponse
{
$limit = (int) ($request->validated()['limit'] ?? 20);
$limit = (int) ($request->validated()['limit'] ?? 20);
$cacheKey = 'tags.popular.' . $limit;
$tags = Tag::query()
->where('is_active', true)
->orderByDesc('usage_count')
->limit($limit)
->get(['id', 'name', 'slug', 'usage_count']);
$data = Cache::remember($cacheKey, 300, function () use ($limit): mixed {
return Tag::query()
->where('is_active', true)
->orderByDesc('usage_count')
->limit($limit)
->get(['id', 'name', 'slug', 'usage_count']);
});
return response()->json([
'data' => $tags,
]);
return response()->json(['data' => $data]);
}
}

View File

@@ -8,6 +8,24 @@ use Illuminate\Support\Facades\DB;
class InterviewController extends Controller
{
public function index(Request $request)
{
try {
$interviews = DB::table('interviews as i')
->leftJoin('users as u', 'u.username', '=', 'i.username')
->select('i.id', 'i.headline', 'i.username', 'u.id as user_id', 'u.name as uname', 'u.icon')
->orderByDesc('i.id')
->get();
} catch (\Throwable $e) {
$interviews = collect();
}
return view('legacy.interviews', [
'interviews' => $interviews,
'page_title' => 'Interviews',
]);
}
public function show(Request $request, $id, $slug = null)
{
$id = (int) $id;

View File

@@ -49,6 +49,6 @@ class LatestCommentsController extends Controller
$page_title = 'Latest Comments';
return view('community.latest-comments', compact('page_title', 'comments'));
return view('web.comments.latest', compact('page_title', 'comments'));
}
}

View File

@@ -36,10 +36,11 @@ class LatestController extends Controller
'thumb_url' => $present['url'],
'thumb_srcset' => $present['srcset'] ?? $present['url'],
'uname' => $artwork->user->name ?? 'Skinbase',
'published_at' => $artwork->published_at, // required by CursorPaginator
];
});
return view('community.latest-artworks', [
return view('web.uploads.latest', [
'artworks' => $artworks,
'page_title' => 'Latest Artworks',
]);

View File

@@ -44,6 +44,6 @@ class MembersController extends Controller
});
}
return view('web.browse', compact('page_title', 'artworks'));
return view('web.members.photos', compact('page_title', 'artworks'));
}
}

View File

@@ -14,26 +14,21 @@ class MonthlyCommentatorsController extends Controller
$page = max(1, (int) $request->query('page', 1));
$query = DB::table('artwork_comments as t1')
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
->leftJoin('country as c', 't2.country', '=', 'c.id')
->leftJoin('users as t2', 't1.user_id', '=', 't2.id')
->where('t1.user_id', '>', 0)
->whereRaw("DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= t1.date")
->whereRaw('t1.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
->select(
't2.user_id',
't2.uname',
't2.user_type',
't2.country',
'c.name as country_name',
'c.flag as country_flag',
't2.id as user_id',
DB::raw('COALESCE(t2.username, t2.name, "User") as uname'),
DB::raw('COUNT(*) as num_comments')
)
->groupBy('t1.user_id')
->groupBy('t2.id')
->orderByDesc('num_comments');
$rows = $query->paginate($hits)->withQueryString();
$page_title = 'Monthly Top Commentators';
return view('user.monthly-commentators', compact('page_title', 'rows'));
return view('web.comments.monthly', compact('page_title', 'rows'));
}
}

View File

@@ -5,15 +5,21 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\ProfileUpdateRequest;
use App\Models\Artwork;
use App\Models\ProfileComment;
use App\Models\User;
use App\Services\ArtworkService;
use App\Services\ThumbnailPresenter;
use App\Services\ThumbnailService;
use App\Services\UsernameApprovalService;
use App\Support\AvatarUrl;
use App\Support\UsernamePolicy;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Schema;
use Illuminate\View\View;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password as PasswordRule;
@@ -63,6 +69,66 @@ class ProfileController extends Controller
return redirect()->route('profile.show', ['username' => UsernamePolicy::normalize($username)], 301);
}
/** Toggle follow/unfollow for the profile of $username (auth required). */
public function toggleFollow(Request $request, string $username): JsonResponse
{
$normalized = UsernamePolicy::normalize($username);
$target = User::query()->whereRaw('LOWER(username) = ?', [$normalized])->firstOrFail();
$viewerId = Auth::id();
if ($viewerId === $target->id) {
return response()->json(['error' => 'Cannot follow yourself.'], 422);
}
$exists = DB::table('user_followers')
->where('user_id', $target->id)
->where('follower_id', $viewerId)
->exists();
if ($exists) {
DB::table('user_followers')
->where('user_id', $target->id)
->where('follower_id', $viewerId)
->delete();
$following = false;
} else {
DB::table('user_followers')->insertOrIgnore([
'user_id' => $target->id,
'follower_id'=> $viewerId,
'created_at' => now(),
]);
$following = true;
}
$count = DB::table('user_followers')->where('user_id', $target->id)->count();
return response()->json([
'following' => $following,
'follower_count' => $count,
]);
}
/** Store a comment on a user profile (auth required). */
public function storeComment(Request $request, string $username): RedirectResponse
{
$normalized = UsernamePolicy::normalize($username);
$target = User::query()->whereRaw('LOWER(username) = ?', [$normalized])->firstOrFail();
$request->validate([
'body' => ['required', 'string', 'min:2', 'max:2000'],
]);
ProfileComment::create([
'profile_user_id' => $target->id,
'author_user_id' => Auth::id(),
'body' => $request->input('body'),
]);
return Redirect::route('profile.show', ['username' => strtolower((string) $target->username)])
->with('status', 'Comment posted!');
}
public function edit(Request $request): View
{
return view('profile.edit', [
@@ -256,38 +322,211 @@ class ProfileController extends Controller
private function renderUserProfile(Request $request, User $user)
{
$isOwner = Auth::check() && Auth::id() === $user->id;
$perPage = 24;
$isOwner = Auth::check() && Auth::id() === $user->id;
$viewer = Auth::user();
$perPage = 24;
// ── Artworks (cursor-paginated) ──────────────────────────────────────
$artworks = $this->artworkService->getArtworksByUser($user->id, $isOwner, $perPage)
->through(function (Artwork $art) {
$present = \App\Services\ThumbnailPresenter::present($art, 'md');
$present = ThumbnailPresenter::present($art, 'md');
return (object) [
'id' => $art->id,
'name' => $art->title,
'picture' => $art->file_name,
'datum' => $art->published_at,
'published_at' => $art->published_at, // required by cursor paginator (orders by this column)
'thumb' => $present['url'],
'thumb_srcset' => $present['srcset'] ?? $present['url'],
'uname' => $art->user->name ?? 'Skinbase',
'username' => $art->user->username ?? null,
'user_id' => $art->user_id,
'width' => $art->width,
'height' => $art->height,
];
});
return (object) [
'id' => $art->id,
'name' => $art->title,
'picture' => $art->file_name,
'datum' => $art->published_at,
'thumb' => $present['url'],
'thumb_srcset' => $present['srcset'] ?? $present['url'],
'uname' => $art->user->name ?? 'Skinbase',
];
});
// ── Featured artworks for this user ─────────────────────────────────
$featuredArtworks = collect();
if (Schema::hasTable('artwork_features')) {
$featuredArtworks = DB::table('artwork_features as af')
->join('artworks as a', 'a.id', '=', 'af.artwork_id')
->where('a.user_id', $user->id)
->where('af.is_active', true)
->whereNull('af.deleted_at')
->whereNull('a.deleted_at')
->where('a.is_public', true)
->where('a.is_approved', true)
->orderByDesc('af.featured_at')
->limit(3)
->select([
'a.id', 'a.title as name', 'a.hash', 'a.thumb_ext',
'a.width', 'a.height', 'af.label', 'af.featured_at',
])
->get()
->map(function ($row) {
$thumbUrl = ($row->hash && $row->thumb_ext)
? ThumbnailService::fromHash($row->hash, $row->thumb_ext, 'md')
: '/images/placeholder.jpg';
return (object) [
'id' => $row->id,
'name' => $row->name,
'thumb' => $thumbUrl,
'label' => $row->label,
'featured_at' => $row->featured_at,
'width' => $row->width,
'height' => $row->height,
];
});
}
$legacyUser = (object) [
'user_id' => $user->id,
'uname' => $user->username ?? $user->name,
'name' => $user->name,
'real_name' => $user->name,
'icon' => DB::table('user_profiles')->where('user_id', $user->id)->value('avatar_hash'),
'about_me' => $user->bio ?? null,
];
// ── Favourites ───────────────────────────────────────────────────────
$favourites = collect();
if (Schema::hasTable('user_favorites')) {
$favourites = DB::table('user_favorites as uf')
->join('artworks as a', 'a.id', '=', 'uf.artwork_id')
->where('uf.user_id', $user->id)
->whereNull('a.deleted_at')
->where('a.is_public', true)
->where('a.is_approved', true)
->orderByDesc('uf.created_at')
->limit(12)
->select(['a.id', 'a.title as name', 'a.hash', 'a.thumb_ext', 'a.width', 'a.height', 'a.user_id'])
->get()
->map(function ($row) {
$thumbUrl = ($row->hash && $row->thumb_ext)
? ThumbnailService::fromHash($row->hash, $row->thumb_ext, 'sm')
: '/images/placeholder.jpg';
return (object) [
'id' => $row->id,
'name' => $row->name,
'thumb' => $thumbUrl,
'width' => $row->width,
'height'=> $row->height,
];
});
}
// ── Statistics ───────────────────────────────────────────────────────
$stats = null;
if (Schema::hasTable('user_statistics')) {
$stats = DB::table('user_statistics')->where('user_id', $user->id)->first();
}
// ── Social links ─────────────────────────────────────────────────────
$socialLinks = collect();
if (Schema::hasTable('user_social_links')) {
$socialLinks = DB::table('user_social_links')
->where('user_id', $user->id)
->get()
->keyBy('platform');
}
// ── Follower data ────────────────────────────────────────────────────
$followerCount = 0;
$recentFollowers = collect();
$viewerIsFollowing = false;
if (Schema::hasTable('user_followers')) {
$followerCount = DB::table('user_followers')->where('user_id', $user->id)->count();
$recentFollowers = DB::table('user_followers as uf')
->join('users as u', 'u.id', '=', 'uf.follower_id')
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
->where('uf.user_id', $user->id)
->whereNull('u.deleted_at')
->orderByDesc('uf.created_at')
->limit(10)
->select(['u.id', 'u.username', 'u.name', 'up.avatar_hash', 'uf.created_at as followed_at'])
->get()
->map(fn ($row) => (object) [
'id' => $row->id,
'username' => $row->username,
'uname' => $row->username ?? $row->name,
'avatar_url' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 50),
'profile_url' => '/@' . strtolower((string) ($row->username ?? $row->id)),
'followed_at' => $row->followed_at,
]);
if ($viewer && $viewer->id !== $user->id) {
$viewerIsFollowing = DB::table('user_followers')
->where('user_id', $user->id)
->where('follower_id', $viewer->id)
->exists();
}
}
// ── Profile comments ─────────────────────────────────────────────────
$profileComments = collect();
if (Schema::hasTable('profile_comments')) {
$profileComments = DB::table('profile_comments as pc')
->join('users as u', 'u.id', '=', 'pc.author_user_id')
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
->where('pc.profile_user_id', $user->id)
->where('pc.is_active', true)
->whereNull('u.deleted_at')
->orderByDesc('pc.created_at')
->limit(10)
->select([
'pc.id', 'pc.body', 'pc.created_at',
'u.id as author_id', 'u.username as author_username', 'u.name as author_name',
'up.avatar_hash as author_avatar_hash', 'up.signature as author_signature',
])
->get()
->map(fn ($row) => (object) [
'id' => $row->id,
'body' => $row->body,
'created_at' => $row->created_at,
'author_id' => $row->author_id,
'author_name' => $row->author_username ?? $row->author_name ?? 'Unknown',
'author_profile_url' => '/@' . strtolower((string) ($row->author_username ?? $row->author_id)),
'author_avatar' => AvatarUrl::forUser((int) $row->author_id, $row->author_avatar_hash, 50),
'author_signature' => $row->author_signature,
]);
}
// ── Profile data ─────────────────────────────────────────────────────
$profile = $user->profile;
// ── Country name (from old country_list table if available) ──────────
$countryName = null;
if ($profile?->country_code) {
if (Schema::hasTable('country_list')) {
$countryName = DB::table('country_list')
->where('country_code', $profile->country_code)
->value('country_name');
}
$countryName = $countryName ?? strtoupper((string) $profile->country_code);
}
// ── Increment profile views (async-safe, ignore errors) ──────────────
if (! $isOwner) {
try {
DB::table('user_statistics')
->updateOrInsert(
['user_id' => $user->id],
['profile_views' => DB::raw('COALESCE(profile_views, 0) + 1'), 'updated_at' => now()]
);
} catch (\Throwable) {}
}
return response()->view('legacy.profile', [
'user' => $legacyUser,
'artworks' => $artworks,
'page_title' => 'Profile: ' . ($legacyUser->uname ?? ''),
'page_canonical' => url('/@' . strtolower((string) ($user->username ?? ''))),
'user' => $user,
'profile' => $profile,
'artworks' => $artworks,
'featuredArtworks' => $featuredArtworks,
'favourites' => $favourites,
'stats' => $stats,
'socialLinks' => $socialLinks,
'followerCount' => $followerCount,
'recentFollowers' => $recentFollowers,
'viewerIsFollowing' => $viewerIsFollowing,
'profileComments' => $profileComments,
'countryName' => $countryName,
'isOwner' => $isOwner,
'page_title' => 'Profile: ' . ($user->username ?? $user->name ?? ''),
'page_canonical' => url('/@' . strtolower((string) ($user->username ?? ''))),
'page_meta_description' => 'View the profile of ' . ($user->username ?? $user->name) . ' on Skinbase.org — artworks, favourites and more.',
]);
}
}

View File

@@ -59,6 +59,6 @@ class TodayDownloadsController extends Controller
$page_title = 'Today Downloaded Artworks';
return view('web.browse', ['page_title' => $page_title, 'artworks' => $paginator]);
return view('web.downloads.today', ['page_title' => $page_title, 'artworks' => $paginator]);
}
}

View File

@@ -45,7 +45,7 @@ class TodayInHistoryController extends Controller
});
}
return view('user.today-in-history', [
return view('legacy.today-in-history', [
'artworks' => $artworks,
'page_title' => 'Popular on this day in history',
]);

View File

@@ -21,7 +21,6 @@ class TopAuthorsController extends Controller
}
$sub = Artwork::query()
->select('artworks.user_id')
->join('artwork_stats', 'artwork_stats.artwork_id', '=', 'artworks.id')
->where('artworks.is_public', true)
->where('artworks.is_approved', true)
@@ -52,6 +51,6 @@ class TopAuthorsController extends Controller
$page_title = 'Top Authors';
return view('user.top-authors', compact('page_title', 'authors', 'metric'));
return view('web.authors.top', compact('page_title', 'authors', 'metric'));
}
}

View File

@@ -51,6 +51,6 @@ class TopFavouritesController extends Controller
$page_title = 'Top Favourites';
return view('user.top-favourites', ['page_title' => $page_title, 'artworks' => $paginator]);
return view('legacy.top-favourites', ['page_title' => $page_title, 'artworks' => $paginator]);
}
}

View File

@@ -7,6 +7,7 @@ namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Http\Resources\ArtworkResource;
use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Services\ThumbnailPresenter;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -102,6 +103,27 @@ final class ArtworkPageController extends Controller
->values()
->all();
$comments = ArtworkComment::with(['user.profile'])
->where('artwork_id', $artwork->id)
->where('is_approved', true)
->orderBy('created_at')
->limit(500)
->get()
->map(fn(ArtworkComment $c) => [
'id' => $c->id,
'content' => (string) $c->content,
'created_at' => $c->created_at?->toIsoString(),
'user' => [
'id' => $c->user?->id,
'name' => $c->user?->name,
'username' => $c->user?->username,
'profile_url' => $c->user?->username ? '/@' . $c->user->username : null,
'avatar_url' => $c->user?->profile?->avatar_url,
],
])
->values()
->all();
return view('artworks.show', [
'artwork' => $artwork,
'artworkData' => $artworkData,
@@ -111,6 +133,7 @@ final class ArtworkPageController extends Controller
'presentSq' => $thumbSq,
'meta' => $meta,
'relatedItems' => $related,
'comments' => $comments,
]);
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Category;
use App\Models\ContentType;
use App\Models\Artwork;
use App\Services\ArtworkService;
use App\Services\ArtworkSearchService;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Pagination\AbstractPaginator;
@@ -15,8 +16,17 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
{
private const CONTENT_TYPE_SLUGS = ['photography', 'wallpapers', 'skins', 'other'];
public function __construct(private ArtworkService $artworks)
{
private const SORT_MAP = [
'latest' => 'created_at:desc',
'popular' => 'views:desc',
'liked' => 'likes:desc',
'downloads' => 'downloads:desc',
];
public function __construct(
private ArtworkService $artworks,
private ArtworkSearchService $search,
) {
}
public function browse(Request $request)
@@ -24,7 +34,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
$sort = (string) $request->query('sort', 'latest');
$perPage = $this->resolvePerPage($request);
$artworks = $this->artworks->browsePublicArtworks($perPage, $sort);
$artworks = Artwork::search('')->options([
'filter' => 'is_public = true AND is_approved = true',
'sort' => [self::SORT_MAP[$sort] ?? 'created_at:desc'],
])->paginate($perPage);
$seo = $this->buildPaginationSeo($request, url('/browse'), $artworks);
$mainCategories = $this->mainCategories();
@@ -69,7 +82,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
$normalizedPath = trim((string) $path, '/');
if ($normalizedPath === '') {
$artworks = $this->artworks->getArtworksByContentType($contentSlug, $perPage, $sort);
$artworks = Artwork::search('')->options([
'filter' => 'is_public = true AND is_approved = true AND content_type = "' . $contentSlug . '"',
'sort' => [self::SORT_MAP[$sort] ?? 'created_at:desc'],
])->paginate($perPage);
$seo = $this->buildPaginationSeo($request, url('/' . $contentSlug), $artworks);
return view('gallery.index', [
@@ -98,7 +114,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
abort(404);
}
$artworks = $this->artworks->getArtworksByCategoryPath(array_merge([$contentSlug], $segments), $perPage, $sort);
$artworks = Artwork::search('')->options([
'filter' => 'is_public = true AND is_approved = true AND category = "' . $category->slug . '"',
'sort' => [self::SORT_MAP[$sort] ?? 'created_at:desc'],
])->paginate($perPage);
$seo = $this->buildPaginationSeo($request, url('/' . $contentSlug . '/' . strtolower($category->full_slug_path)), $artworks);
$subcategories = $category->children()->orderBy('sort_order')->orderBy('name')->get();

View File

@@ -17,6 +17,11 @@ class CategoryController extends Controller
$this->artworkService = $artworkService;
}
public function index(Request $request)
{
return $this->browseCategories();
}
public function show(Request $request, $id, $slug = null, $group = null)
{
$path = trim($request->path(), '/');

View File

@@ -27,17 +27,20 @@ class HomeController extends Controller
$featuredResult = $this->artworks->getFeaturedArtworks(null, 39);
if ($featuredResult instanceof \Illuminate\Pagination\LengthAwarePaginator) {
$featured = $featuredResult->getCollection()->first();
$featuredCollection = $featuredResult->getCollection();
$featured = $featuredCollection->get(0);
$memberFeatured = $featuredCollection->get(1);
} elseif (is_array($featuredResult)) {
$featured = $featuredResult[0] ?? null;
$memberFeatured = $featuredResult[1] ?? null;
} elseif ($featuredResult instanceof Collection) {
$featured = $featuredResult->first();
$featured = $featuredResult->get(0);
$memberFeatured = $featuredResult->get(1);
} else {
$featured = $featuredResult;
$memberFeatured = null;
}
$memberFeatured = $featured;
$latestUploads = $this->artworks->getLatestArtworks(20);
// Forum news (prefer migrated legacy news category id 2876, fallback to slug)

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Services\ArtworkSearchService;
use Illuminate\Http\Request;
use Illuminate\View\View;
final class SearchController extends Controller
{
public function __construct(private readonly ArtworkSearchService $search) {}
public function index(Request $request): View
{
$q = trim((string) $request->query('q', ''));
$sort = $request->query('sort', 'latest');
$sortMap = [
'popular' => 'views:desc',
'likes' => 'likes:desc',
'latest' => 'created_at:desc',
'downloads' => 'downloads:desc',
];
$artworks = null;
$popular = collect();
if ($q !== '') {
$artworks = $this->search->search($q, [
'sort' => ($sortMap[$sort] ?? 'created_at:desc'),
]);
} else {
$popular = $this->search->popular(16)->getCollection();
}
return view('search.index', [
'q' => $q,
'sort' => $sort,
'artworks' => $artworks ?? collect()->paginate(0),
'popular' => $popular,
'page_title' => $q !== '' ? 'Search: ' . $q . ' — Skinbase' : 'Search — Skinbase',
'page_meta_description' => 'Search Skinbase for artworks, photography, wallpapers and skins.',
'page_robots' => 'noindex,follow',
]);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\ContentType;
use Illuminate\Support\Facades\DB;
class SectionsController extends Controller
{
public function index()
{
// Load all content types with full category tree (roots + children)
$contentTypes = ContentType::with([
'rootCategories' => function ($q) {
$q->active()
->withCount(['artworks as artwork_count'])
->orderBy('sort_order')
->orderBy('name');
},
'rootCategories.children' => function ($q) {
$q->active()
->withCount(['artworks as artwork_count'])
->orderBy('sort_order')
->orderBy('name');
},
])->orderBy('id')->get();
// Total artwork counts per content type via a single aggregation query
$artworkCountsByType = DB::table('artworks')
->join('artwork_category', 'artworks.id', '=', 'artwork_category.artwork_id')
->join('categories', 'artwork_category.category_id', '=', 'categories.id')
->where('artworks.is_approved', true)
->where('artworks.is_public', true)
->whereNull('artworks.deleted_at')
->select('categories.content_type_id', DB::raw('COUNT(DISTINCT artworks.id) as total'))
->groupBy('categories.content_type_id')
->pluck('total', 'content_type_id');
return view('web.sections', [
'contentTypes' => $contentTypes,
'artworkCountsByType' => $artworkCountsByType,
'page_title' => 'Browse Sections',
'page_meta_description' => 'Browse all artwork sections on Skinbase — Photography, Wallpapers, Skins and more.',
]);
}
}

View File

@@ -6,24 +6,57 @@ namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Tag;
use App\Services\ArtworkSearchService;
use Illuminate\Http\Request;
use Illuminate\View\View;
final class TagController extends Controller
{
public function show(Tag $tag): View
public function __construct(private readonly ArtworkSearchService $search) {}
public function show(Tag $tag, Request $request): View
{
$artworks = $tag->artworks()
->public()
->published()
->leftJoin('artwork_stats', 'artwork_stats.artwork_id', '=', 'artworks.id')
->orderByDesc('artwork_stats.views')
->orderByDesc('artworks.published_at')
->select('artworks.*')
->paginate(24);
$sort = $request->query('sort', 'popular'); // popular | latest | downloads
$perPage = min((int) $request->query('per_page', 24), 100);
// Convert sort param to Meili sort expression
$sortMap = [
'popular' => 'views:desc',
'likes' => 'likes:desc',
'latest' => 'created_at:desc',
'downloads' => 'downloads:desc',
];
$meiliSort = $sortMap[$sort] ?? 'views:desc';
$artworks = \App\Models\Artwork::search('')
->options([
'filter' => 'is_public = true AND is_approved = true AND tags = "' . addslashes($tag->slug) . '"',
'sort' => [$meiliSort],
])
->paginate($perPage)
->appends(['sort' => $sort]);
// Eager-load relations needed by the artwork-card component.
// Scout returns bare Eloquent models; without this, each card triggers N+1 queries.
$artworks->getCollection()->loadMissing(['user.profile']);
// OG image: first result's thumbnail
$ogImage = null;
if ($artworks->count() > 0) {
$first = $artworks->getCollection()->first();
$ogImage = $first?->thumbUrl('md');
}
return view('tags.show', [
'tag' => $tag,
'tag' => $tag,
'artworks' => $artworks,
'sort' => $sort,
'ogImage' => $ogImage,
'page_title' => 'Artworks tagged "' . $tag->name . '" — Skinbase',
'page_meta_description' => 'Browse all Skinbase artworks tagged "' . $tag->name . '". Discover photography, wallpapers and skins.',
'page_canonical' => route('tags.show', $tag->slug),
'page_robots' => 'index,follow',
]);
}
}

View File

@@ -5,17 +5,12 @@ declare(strict_types=1);
namespace App\Http\Requests\Tags;
use Illuminate\Foundation\Http\FormRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class PopularTagsRequest extends FormRequest
{
public function authorize(): bool
{
if (! $this->user()) {
throw new NotFoundHttpException();
}
return true;
return true; // public endpoint
}
public function rules(): array

View File

@@ -5,17 +5,12 @@ declare(strict_types=1);
namespace App\Http\Requests\Tags;
use Illuminate\Foundation\Http\FormRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class TagSearchRequest extends FormRequest
{
public function authorize(): bool
{
if (! $this->user()) {
throw new NotFoundHttpException();
}
return true;
return true; // public endpoint
}
public function rules(): array