Current state
This commit is contained in:
46
app/Http/Controllers/Api/ArtworkController.php
Normal file
46
app/Http/Controllers/Api/ArtworkController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\ArtworkListResource;
|
||||
use App\Http\Resources\ArtworkResource;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArtworkController extends Controller
|
||||
{
|
||||
protected ArtworkService $service;
|
||||
|
||||
public function __construct(ArtworkService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/artworks/{slug}
|
||||
* Returns a single public artwork resource by slug.
|
||||
*/
|
||||
public function show(string $slug)
|
||||
{
|
||||
$artwork = $this->service->getPublicArtworkBySlug($slug);
|
||||
|
||||
// Return the artwork instance (service already loads lightweight relations).
|
||||
// Log resolved resource for debugging failing test assertions.
|
||||
// Return the resolved payload directly to avoid JsonResource wrapping inconsistencies
|
||||
return response()->json((new ArtworkResource($artwork))->resolve(), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/categories/{slug}/artworks
|
||||
* Uses route-model binding for Category (slug). Returns paginated list resource.
|
||||
*/
|
||||
public function categoryArtworks(Request $request, Category $category)
|
||||
{
|
||||
$perPage = (int) $request->get('per_page', 24);
|
||||
|
||||
$paginator = $this->service->getCategoryArtworks($category, $perPage);
|
||||
|
||||
return ArtworkListResource::collection($paginator);
|
||||
}
|
||||
}
|
||||
78
app/Http/Controllers/Api/BrowseController.php
Normal file
78
app/Http/Controllers/Api/BrowseController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\ArtworkListResource;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class BrowseController extends Controller
|
||||
{
|
||||
protected ArtworkService $service;
|
||||
|
||||
public function __construct(ArtworkService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/browse
|
||||
* Public browse feed powered by authoritative artworks table.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
|
||||
|
||||
$paginator = $this->service->browsePublicArtworks($perPage);
|
||||
|
||||
return ArtworkListResource::collection($paginator);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/browse/{content_type}
|
||||
* Browse by content type slug.
|
||||
*/
|
||||
public function byContentType(Request $request, string $contentTypeSlug)
|
||||
{
|
||||
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
|
||||
|
||||
try {
|
||||
$paginator = $this->service->getArtworksByContentType($contentTypeSlug, $perPage);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($paginator->count() === 0) {
|
||||
return response()->json(['message' => 'Gone'], 410);
|
||||
}
|
||||
|
||||
return ArtworkListResource::collection($paginator);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/browse/{content_type}/{category_path}
|
||||
* Browse by content type + category path (slug segments).
|
||||
*/
|
||||
public function byCategoryPath(Request $request, string $contentTypeSlug, string $categoryPath)
|
||||
{
|
||||
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
|
||||
|
||||
$slugs = array_merge([
|
||||
strtolower($contentTypeSlug),
|
||||
], array_values(array_filter(explode('/', trim($categoryPath, '/')))));
|
||||
|
||||
try {
|
||||
$paginator = $this->service->getArtworksByCategoryPath($slugs, $perPage);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($paginator->count() === 0) {
|
||||
return response()->json(['message' => 'Gone'], 410);
|
||||
}
|
||||
|
||||
return ArtworkListResource::collection($paginator);
|
||||
}
|
||||
}
|
||||
64
app/Http/Controllers/ArtworkController.php
Normal file
64
app/Http/Controllers/ArtworkController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ArtworkIndexRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ArtworkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Browse artworks with optional category filtering.
|
||||
* Uses cursor pagination (no offset pagination) and only returns public, approved, not-deleted items.
|
||||
*/
|
||||
public function index(ArtworkIndexRequest $request, ?Category $category = null): View
|
||||
{
|
||||
$perPage = (int) ($request->get('per_page', 24));
|
||||
|
||||
$query = Artwork::public()->published();
|
||||
|
||||
if ($category) {
|
||||
$query->whereHas('categories', function ($q) use ($category) {
|
||||
$q->where('categories.id', $category->id);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$q = $request->get('q');
|
||||
$query->where(function ($sub) use ($q) {
|
||||
$sub->where('title', 'like', '%' . $q . '%')
|
||||
->orWhere('description', 'like', '%' . $q . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$sort = $request->get('sort', 'latest');
|
||||
if ($sort === 'oldest') {
|
||||
$query->orderBy('published_at', 'asc');
|
||||
} else {
|
||||
$query->orderByDesc('published_at');
|
||||
}
|
||||
|
||||
// Important: do NOT eager-load artwork_stats in listings
|
||||
$artworks = $query->cursorPaginate($perPage);
|
||||
|
||||
return view('artworks.index', [
|
||||
'artworks' => $artworks,
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single artwork by slug. Ensure it's public, approved and not deleted.
|
||||
*/
|
||||
public function show(Artwork $artwork): View
|
||||
{
|
||||
if (! $artwork->is_public || ! $artwork->is_approved || $artwork->trashed()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return view('artworks.show', ['artwork' => $artwork]);
|
||||
}
|
||||
}
|
||||
47
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
47
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
40
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
40
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
62
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
62
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
29
app/Http/Controllers/Auth/PasswordController.php
Normal file
29
app/Http/Controllers/Auth/PasswordController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
44
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
44
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
50
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
50
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
27
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
27
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
34
app/Http/Controllers/BrowseCategoriesController.php
Normal file
34
app/Http/Controllers/BrowseCategoriesController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BrowseCategoriesController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Use Eloquent models for canonical category URLs and grouping
|
||||
$contentTypes = \App\Models\ContentType::with(['rootCategories.children'])->orderBy('id')->get();
|
||||
|
||||
// Prepare categories grouped by content type and a flat list of root categories
|
||||
$categoriesByType = [];
|
||||
$categories = collect();
|
||||
foreach ($contentTypes as $ct) {
|
||||
$rootCats = $ct->rootCategories;
|
||||
foreach ($rootCats as $cat) {
|
||||
// Attach subcategories
|
||||
$cat->subcategories = $cat->children;
|
||||
$categories->push($cat);
|
||||
}
|
||||
$categoriesByType[$ct->slug] = $rootCats;
|
||||
}
|
||||
|
||||
return view('browse-categories', [
|
||||
'contentTypes' => $contentTypes,
|
||||
'categoriesByType' => $categoriesByType,
|
||||
'categories' => $categories,
|
||||
]);
|
||||
}
|
||||
}
|
||||
81
app/Http/Controllers/CategoryPageController.php
Normal file
81
app/Http/Controllers/CategoryPageController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\ContentType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class CategoryPageController extends Controller
|
||||
{
|
||||
public function show(Request $request, string $contentTypeSlug, string $categoryPath = null)
|
||||
{
|
||||
$contentType = ContentType::where('slug', strtolower($contentTypeSlug))->first();
|
||||
if (! $contentType) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($categoryPath === null || $categoryPath === '') {
|
||||
// No category path: show content-type landing page (e.g., /wallpapers)
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
$page_title = $contentType->name;
|
||||
$page_meta_description = $contentType->description ?? ($contentType->name . ' artworks on Skinbase');
|
||||
|
||||
return view('legacy.content-type', compact(
|
||||
'contentType',
|
||||
'rootCategories',
|
||||
'page_title',
|
||||
'page_meta_description'
|
||||
));
|
||||
}
|
||||
|
||||
$segments = array_filter(explode('/', $categoryPath));
|
||||
if (empty($segments)) {
|
||||
return redirect('/browse-categories');
|
||||
}
|
||||
|
||||
// Traverse categories by slug path within the content type
|
||||
$current = Category::where('content_type_id', $contentType->id)
|
||||
->whereNull('parent_id')
|
||||
->where('slug', strtolower(array_shift($segments)))
|
||||
->first();
|
||||
|
||||
if (! $current) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
foreach ($segments as $slug) {
|
||||
$current = $current->children()->where('slug', strtolower($slug))->first();
|
||||
if (! $current) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
$category = $current;
|
||||
$subcategories = $category->children()->orderBy('sort_order')->orderBy('name')->get();
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
|
||||
// Placeholder artworks paginator (until artwork data is wired).
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
$artworks = new LengthAwarePaginator([], 0, 40, $page, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]);
|
||||
|
||||
$page_title = $category->name;
|
||||
$page_meta_description = $category->description ?? ($contentType->name . ' artworks on Skinbase');
|
||||
$page_meta_keywords = strtolower($contentType->slug) . ', skinbase, artworks, wallpapers, skins, photography';
|
||||
|
||||
return view('legacy.category-slug', compact(
|
||||
'contentType',
|
||||
'category',
|
||||
'subcategories',
|
||||
'rootCategories',
|
||||
'artworks',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
62
app/Http/Controllers/Legacy/ArtController.php
Normal file
62
app/Http/Controllers/Legacy/ArtController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\LegacyService;
|
||||
|
||||
class ArtController extends Controller
|
||||
{
|
||||
protected LegacyService $legacy;
|
||||
|
||||
public function __construct(LegacyService $legacy)
|
||||
{
|
||||
$this->legacy = $legacy;
|
||||
}
|
||||
|
||||
public function show(Request $request, $id, $slug = null)
|
||||
{
|
||||
// handle comment POST from legacy form
|
||||
if ($request->isMethod('post') && $request->input('action') === 'store_comment') {
|
||||
if (auth()->check()) {
|
||||
try {
|
||||
\Illuminate\Support\Facades\DB::connection('legacy')->table('artworks_comments')->insert([
|
||||
'artwork_id' => (int)$id,
|
||||
'owner_user_id' => (int)($request->user()->id ?? 0),
|
||||
'user_id' => (int)$request->user()->id,
|
||||
'date' => now()->toDateString(),
|
||||
'time' => now()->toTimeString(),
|
||||
'description' => (string)$request->input('comment_text'),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
// ignore DB errors for now
|
||||
}
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$data = $this->legacy->getArtwork((int) $id);
|
||||
|
||||
if (! $data || empty($data['artwork'])) {
|
||||
return view('legacy.placeholder', ['title' => 'Artwork Not Found']);
|
||||
}
|
||||
|
||||
// load comments for artwork (legacy schema)
|
||||
try {
|
||||
$comments = \Illuminate\Support\Facades\DB::connection('legacy')->table('artworks_comments as t1')
|
||||
->rightJoin('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->select('t1.description', 't1.date', 't1.time', 't2.uname', 't2.signature', 't2.icon', 't2.user_id')
|
||||
->where('t1.artwork_id', (int)$id)
|
||||
->where('t1.user_id', '>', 0)
|
||||
->orderBy('t1.comment_id')
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$comments = collect();
|
||||
}
|
||||
|
||||
$data['comments'] = $comments;
|
||||
|
||||
return view('legacy.art', $data);
|
||||
}
|
||||
}
|
||||
67
app/Http/Controllers/Legacy/AvatarController.php
Normal file
67
app/Http/Controllers/Legacy/AvatarController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AvatarController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $name = null)
|
||||
{
|
||||
$user_id = (int) $id;
|
||||
|
||||
// default avatar in project public gfx
|
||||
$defaultAvatar = public_path('gfx/avatar.jpg');
|
||||
|
||||
try {
|
||||
$icon = DB::connection('legacy')->table('users')->where('user_id', $user_id)->value('icon');
|
||||
} catch (\Throwable $e) {
|
||||
$icon = null;
|
||||
}
|
||||
|
||||
$candidates = [];
|
||||
if (!empty($icon)) {
|
||||
// common legacy locations to check
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . $icon);
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . rawurlencode($icon));
|
||||
$candidates[] = base_path('oldSite/www/files/usericons/' . basename($icon));
|
||||
$candidates[] = public_path('avatar/' . $user_id . '/' . $icon);
|
||||
$candidates[] = public_path('avatar/' . $user_id . '/' . basename($icon));
|
||||
$candidates[] = storage_path('app/public/usericons/' . $icon);
|
||||
$candidates[] = storage_path('app/public/usericons/' . basename($icon));
|
||||
}
|
||||
|
||||
// find first readable file
|
||||
$found = null;
|
||||
foreach ($candidates as $path) {
|
||||
if ($path && file_exists($path) && is_readable($path)) {
|
||||
$found = $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
$type = @exif_imagetype($found);
|
||||
if ($type) {
|
||||
$mime = image_type_to_mime_type($type);
|
||||
} else {
|
||||
$f = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$mime = finfo_file($f, $found) ?: 'application/octet-stream';
|
||||
finfo_close($f);
|
||||
}
|
||||
|
||||
return response()->file($found, ['Content-Type' => $mime]);
|
||||
}
|
||||
|
||||
// fallback to default
|
||||
if (file_exists($defaultAvatar) && is_readable($defaultAvatar)) {
|
||||
return response()->file($defaultAvatar, ['Content-Type' => 'image/jpeg']);
|
||||
}
|
||||
|
||||
// final fallback: 404
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
85
app/Http/Controllers/Legacy/BrowseController.php
Normal file
85
app/Http/Controllers/Legacy/BrowseController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\CursorPaginator;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BrowseController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$page_title = 'Browse Uploaded Artworks - Photography, Wallpapers and Skins at SkinBase';
|
||||
$page_meta_description = "Browse Uploaded Photography, Wallpapers and Skins to one of the world's oldest online social community for artists and art enthusiasts.";
|
||||
$page_meta_keywords = 'photography, wallpapers, skins, stock, browse, social, community, artist, picture, photo';
|
||||
|
||||
$perPage = (int) $request->get('per_page', 24);
|
||||
|
||||
$categoryPath = trim((string) $request->query('category', ''), '/');
|
||||
|
||||
try {
|
||||
if ($categoryPath !== '') {
|
||||
$slugs = array_values(array_filter(explode('/', $categoryPath)));
|
||||
/** @var CursorPaginator $artworks */
|
||||
$artworks = $this->artworks->getArtworksByCategoryPath($slugs, $perPage);
|
||||
} else {
|
||||
/** @var CursorPaginator $artworks */
|
||||
$artworks = $this->artworks->browsePublicArtworks($perPage);
|
||||
}
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (count($artworks) === 0) {
|
||||
Log::warning('browse.missing_artworks', [
|
||||
'url' => $request->fullUrl(),
|
||||
'category_path' => $categoryPath ?: null,
|
||||
]);
|
||||
abort(410);
|
||||
}
|
||||
|
||||
// Shape data for the legacy Blade while using authoritative tables only.
|
||||
$artworks->getCollection()->transform(fn (Artwork $artwork) => $this->mapArtwork($artwork));
|
||||
|
||||
return view('legacy.browse', compact('page_title', 'page_meta_description', 'page_meta_keywords', 'artworks'));
|
||||
}
|
||||
|
||||
private function mapArtwork(Artwork $artwork): object
|
||||
{
|
||||
$primaryCategory = $artwork->categories->sortBy('sort_order')->first();
|
||||
$categoryPath = $primaryCategory?->full_slug_path;
|
||||
$contentTypeSlug = $primaryCategory?->contentType?->slug;
|
||||
$webUrl = $contentTypeSlug && $categoryPath
|
||||
? '/' . strtolower($contentTypeSlug) . '/' . strtolower($categoryPath) . '/' . $artwork->slug
|
||||
: null;
|
||||
|
||||
$present = \App\Services\ThumbnailPresenter::present($artwork, 'md');
|
||||
|
||||
return (object) [
|
||||
'id' => $artwork->id,
|
||||
// Include ordering parameter used by cursor paginator so links can be generated
|
||||
'published_at' => $artwork->published_at?->toAtomString(),
|
||||
'slug' => $artwork->slug,
|
||||
'name' => $artwork->title,
|
||||
'category_name' => $primaryCategory->name ?? '',
|
||||
'gid_num' => $primaryCategory ? ((int) $primaryCategory->id % 5) * 5 : 0,
|
||||
'thumb' => $present['url'],
|
||||
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
||||
'uname' => $artwork->user->name ?? 'Skinbase',
|
||||
'url' => $webUrl ?? '#',
|
||||
];
|
||||
}
|
||||
}
|
||||
108
app/Http/Controllers/Legacy/CategoryController.php
Normal file
108
app/Http/Controllers/Legacy/CategoryController.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworkService;
|
||||
|
||||
public function __construct(ArtworkService $artworkService)
|
||||
{
|
||||
$this->artworkService = $artworkService;
|
||||
}
|
||||
|
||||
public function show(Request $request, $id, $slug = null, $group = null)
|
||||
{
|
||||
// Parse request path after '/category' to support unlimited depth and legacy routes
|
||||
$path = trim($request->path(), '/');
|
||||
$segments = array_values(array_filter(explode('/', $path)));
|
||||
|
||||
// Expecting segments like ['category', '{contentType}', '{...categorySlugs}']
|
||||
if (count($segments) < 2 || strtolower($segments[0]) !== 'category') {
|
||||
return view('legacy.placeholder');
|
||||
}
|
||||
|
||||
$parts = array_slice($segments, 1);
|
||||
|
||||
// If first part is numeric, attempt id->category resolution and redirect to canonical slug URL
|
||||
$first = $parts[0] ?? null;
|
||||
if ($first !== null && ctype_digit((string) $first)) {
|
||||
try {
|
||||
$category = Category::findOrFail((int) $first);
|
||||
$contentTypeSlug = $category->contentType->slug ?? null;
|
||||
$canonical = '/' . strtolower($contentTypeSlug) . '/' . $category->full_slug_path;
|
||||
return redirect($canonical, 301);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
// Build slug list: first element is content type slug, rest are category slugs
|
||||
$contentTypeSlug = array_shift($parts);
|
||||
$slugs = array_merge([$contentTypeSlug], $parts);
|
||||
|
||||
$perPage = (int) $request->get('per_page', 40);
|
||||
|
||||
try {
|
||||
$artworks = $this->artworkService->getArtworksByCategoryPath($slugs, $perPage);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Resolve Category model for page meta and subcategories
|
||||
// Use the contentType + path traversal to find the category
|
||||
try {
|
||||
$category = Category::whereHas('contentType', function ($q) use ($contentTypeSlug) {
|
||||
$q->where('slug', strtolower($contentTypeSlug));
|
||||
})->whereNull('parent_id')->where('slug', strtolower($parts[0] ?? ''))->first();
|
||||
|
||||
// If deeper path exists, traverse
|
||||
if ($category && count($parts) > 1) {
|
||||
$cur = $category;
|
||||
foreach (array_slice($parts, 1) as $slugPart) {
|
||||
$cur = $cur->children()->where('slug', strtolower($slugPart))->first();
|
||||
if (! $cur) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
$category = $cur;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$category = null;
|
||||
}
|
||||
|
||||
if (! $category) {
|
||||
// Category resolution failed
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$subcategories = $category->children()->orderBy('sort_order')->orderBy('name')->get();
|
||||
|
||||
$page_title = $category->name;
|
||||
$page_meta_description = $category->description ?? ($category->contentType->name . ' artworks on Skinbase');
|
||||
$page_meta_keywords = strtolower($category->contentType->slug) . ', skinbase, artworks, wallpapers, skins, photography';
|
||||
|
||||
return view('legacy.category', compact(
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords',
|
||||
'group',
|
||||
'category',
|
||||
'subcategories',
|
||||
'artworks'
|
||||
));
|
||||
}
|
||||
|
||||
public function browseCategories()
|
||||
{
|
||||
$data = $this->legacy->browseCategories();
|
||||
return view('legacy.categories', $data);
|
||||
}
|
||||
}
|
||||
48
app/Http/Controllers/Legacy/ChatController.php
Normal file
48
app/Http/Controllers/Legacy/ChatController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ChatController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$page_title = 'Online Chat';
|
||||
|
||||
// Handle post (store chat)
|
||||
$store = $request->input('store_chat');
|
||||
$chat_text = $request->input('chat_txt');
|
||||
|
||||
$chat = new \App\Chat();
|
||||
|
||||
if (!empty($store) && $store === 'true' && !empty($chat_text)) {
|
||||
if (!empty($_SESSION['web_login']['status'])) {
|
||||
$chat->StoreMessage($chat_text);
|
||||
$chat->UpdateChatFile('cron/chat_log.txt', 10);
|
||||
}
|
||||
}
|
||||
|
||||
// Capture Banner output
|
||||
ob_start();
|
||||
\App\Banner::ShowResponsiveAd();
|
||||
$adHtml = ob_get_clean();
|
||||
|
||||
// Capture Chat HTML
|
||||
ob_start();
|
||||
$userID = $_SESSION['web_login']['user_id'] ?? null;
|
||||
$chat->ShowChat(50, $userID);
|
||||
$chatHtml = ob_get_clean();
|
||||
|
||||
// Load smileys from legacy DB
|
||||
try {
|
||||
$smileys = DB::connection('legacy')->table('smileys')->select('code', 'picture', 'emotion')->get();
|
||||
} catch (\Throwable $e) {
|
||||
$smileys = collect();
|
||||
}
|
||||
|
||||
return view('legacy.chat', compact('page_title', 'adHtml', 'chatHtml', 'smileys'));
|
||||
}
|
||||
}
|
||||
98
app/Http/Controllers/Legacy/DailyUploadsController.php
Normal file
98
app/Http/Controllers/Legacy/DailyUploadsController.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class DailyUploadsController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$isAjax = $request->boolean('ajax');
|
||||
$datum = $request->query('datum');
|
||||
|
||||
if ($isAjax && $datum) {
|
||||
// Return partial gallery for the given date
|
||||
$arts = $this->fetchByDate($datum);
|
||||
return view('legacy.partials.daily-uploads-grid', ['arts' => $arts])->render();
|
||||
}
|
||||
|
||||
// Build date tabs (today .. -14 days)
|
||||
$dates = [];
|
||||
for ($x = 0; $x > -15; $x--) {
|
||||
$ts = strtotime(sprintf('%+d days', $x));
|
||||
$dates[] = [
|
||||
'iso' => date('Y-m-d', $ts),
|
||||
'label' => date('d. F Y', $ts),
|
||||
];
|
||||
}
|
||||
|
||||
// initial content: recent (last 7 days)
|
||||
$recent = $this->fetchRecent();
|
||||
|
||||
return view('legacy.daily-uploads', [
|
||||
'dates' => $dates,
|
||||
'recent' => $recent,
|
||||
'page_title' => 'Daily Uploads',
|
||||
]);
|
||||
}
|
||||
|
||||
private function fetchByDate(string $date)
|
||||
{
|
||||
$ars = Artwork::public()
|
||||
->published()
|
||||
->whereDate('published_at', $date)
|
||||
->orderByDesc('published_at')
|
||||
->with(['user:id,name', 'categories' => function ($q) {
|
||||
$q->select('categories.id', 'categories.name', 'categories.sort_order');
|
||||
}])
|
||||
->get();
|
||||
|
||||
return $this->prepareArts($ars);
|
||||
}
|
||||
|
||||
private function fetchRecent()
|
||||
{
|
||||
$start = now()->subDays(7)->startOfDay();
|
||||
|
||||
$ars = Artwork::public()
|
||||
->published()
|
||||
->where('published_at', '>=', $start)
|
||||
->orderByDesc('published_at')
|
||||
->with(['user:id,name', 'categories' => function ($q) {
|
||||
$q->select('categories.id', 'categories.name', 'categories.sort_order');
|
||||
}])
|
||||
->get();
|
||||
|
||||
return $this->prepareArts($ars);
|
||||
}
|
||||
|
||||
private function prepareArts($ars)
|
||||
{
|
||||
return $ars->map(function (Artwork $ar) {
|
||||
$primaryCategory = $ar->categories->sortBy('sort_order')->first();
|
||||
$present = \App\Services\ThumbnailPresenter::present($ar, 'md');
|
||||
|
||||
return (object) [
|
||||
'id' => $ar->id,
|
||||
'name' => $ar->title,
|
||||
'thumb' => $present['url'],
|
||||
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
||||
'gid_num' => $primaryCategory ? ((int) $primaryCategory->id % 5) * 5 : 0,
|
||||
'category_name' => $primaryCategory->name ?? '',
|
||||
'uname' => $ar->user->name ?? 'Skinbase',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
63
app/Http/Controllers/Legacy/FeaturedArtworksController.php
Normal file
63
app/Http/Controllers/Legacy/FeaturedArtworksController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FeaturedArtworksController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = 39;
|
||||
|
||||
$type = (int) ($request->query('type', 4));
|
||||
|
||||
$typeFilter = $type === 4 ? null : $type;
|
||||
|
||||
$artworks = $this->artworks->getFeaturedArtworks($typeFilter, $perPage);
|
||||
|
||||
$artworks->getCollection()->transform(function (Artwork $artwork) {
|
||||
$primaryCategory = $artwork->categories->sortBy('sort_order')->first();
|
||||
$categoryName = $primaryCategory->name ?? '';
|
||||
$gid = $primaryCategory ? ((int) $primaryCategory->id % 5) * 5 : 0;
|
||||
$present = \App\Services\ThumbnailPresenter::present($artwork, 'md');
|
||||
|
||||
return (object) [
|
||||
'id' => $artwork->id,
|
||||
'name' => $artwork->title,
|
||||
'category_name' => $categoryName,
|
||||
'gid_num' => $gid,
|
||||
'thumb_url' => $present['url'],
|
||||
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
||||
'uname' => $artwork->user->name ?? 'Skinbase',
|
||||
];
|
||||
});
|
||||
|
||||
$artworkTypes = [
|
||||
1 => 'Bronze Awards',
|
||||
2 => 'Silver Awards',
|
||||
3 => 'Gold Awards',
|
||||
4 => 'Featured Artworks',
|
||||
];
|
||||
|
||||
$pageTitle = $artworkTypes[$type] ?? 'Featured Artworks';
|
||||
|
||||
return view('legacy.featured-artworks', [
|
||||
'artworks' => $artworks,
|
||||
'type' => $type,
|
||||
'artworkTypes' => $artworkTypes,
|
||||
'page_title' => $pageTitle,
|
||||
]);
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/Legacy/ForumController.php
Normal file
38
app/Http/Controllers/Legacy/ForumController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\LegacyService;
|
||||
|
||||
class ForumController extends Controller
|
||||
{
|
||||
protected LegacyService $legacy;
|
||||
|
||||
public function __construct(LegacyService $legacy)
|
||||
{
|
||||
$this->legacy = $legacy;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = $this->legacy->forumIndex();
|
||||
return view('legacy.forum.index', $data);
|
||||
}
|
||||
|
||||
public function topic(Request $request, $topic_id)
|
||||
{
|
||||
$data = $this->legacy->forumTopic((int) $topic_id, (int) $request->query('page', 1));
|
||||
|
||||
if (! $data) {
|
||||
return view('legacy.placeholder');
|
||||
}
|
||||
|
||||
if (isset($data['type']) && $data['type'] === 'subtopics') {
|
||||
return view('legacy.forum.topic', $data);
|
||||
}
|
||||
|
||||
return view('legacy.forum.posts', $data);
|
||||
}
|
||||
}
|
||||
58
app/Http/Controllers/Legacy/HomeController.php
Normal file
58
app/Http/Controllers/Legacy/HomeController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\ArtworkService;
|
||||
|
||||
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';
|
||||
|
||||
// Use new ArtworkService as primary data source
|
||||
$featuredResult = $this->artworks->getFeaturedArtworks(null, 39);
|
||||
// If service returned a paginator, extract the first model for the single "featured" slot
|
||||
if ($featuredResult instanceof \Illuminate\Pagination\LengthAwarePaginator) {
|
||||
$featured = $featuredResult->getCollection()->first();
|
||||
} elseif (is_array($featuredResult)) {
|
||||
$featured = $featuredResult[0] ?? null;
|
||||
} else {
|
||||
// Collection or single item
|
||||
$featured = method_exists($featuredResult, 'first') ? $featuredResult->first() : $featuredResult;
|
||||
}
|
||||
|
||||
// Provide a memberFeatured fallback so the legacy view always has a value
|
||||
$memberFeatured = $featured;
|
||||
|
||||
$latestUploads = $this->artworks->getLatestArtworks(20);
|
||||
|
||||
// Legacy forum/news data not available in new services yet — provide empty defaults
|
||||
$forumNews = [];
|
||||
$ourNews = [];
|
||||
$latestForumActivity = [];
|
||||
|
||||
return view('legacy.home', compact(
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords',
|
||||
'featured',
|
||||
'memberFeatured',
|
||||
'latestUploads',
|
||||
'forumNews',
|
||||
'ourNews',
|
||||
'latestForumActivity'
|
||||
));
|
||||
}
|
||||
}
|
||||
106
app/Http/Controllers/Legacy/InterviewController.php
Normal file
106
app/Http/Controllers/Legacy/InterviewController.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InterviewController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $slug = null)
|
||||
{
|
||||
$id = (int) $id;
|
||||
|
||||
// Handle comment POST
|
||||
if ($request->isMethod('post')) {
|
||||
$action = $request->input('action');
|
||||
if ($action === 'store' && (!empty($_SESSION['web_login']['user_type']) && $_SESSION['web_login']['user_type'] > 1)) {
|
||||
$comment = $request->input('comment');
|
||||
$tekst = nl2br(htmlspecialchars($comment ?? '', ENT_QUOTES, 'UTF-8'));
|
||||
$interviewId = (int) $request->input('interview_id');
|
||||
|
||||
try {
|
||||
DB::connection('legacy')->table('interviews_comment')->insert([
|
||||
'nid' => $interviewId,
|
||||
'author' => $_SESSION['web_login']['username'] ?? 'Anonymous',
|
||||
'datum' => DB::raw('CURRENT_TIMESTAMP'),
|
||||
'tekst' => $tekst,
|
||||
]);
|
||||
|
||||
$ar2 = DB::connection('legacy')->table('users')
|
||||
->where('uname', $_SESSION['web_login']['username'])
|
||||
->first();
|
||||
|
||||
if (!empty($ar2->user_id)) {
|
||||
DB::connection('legacy')->table('users_statistics')
|
||||
->where('user_id', $ar2->user_id)
|
||||
->increment('newscomment');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// fail silently
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$ar = DB::connection('legacy')->table('interviews')->where('id', $id)->first();
|
||||
} catch (\Throwable $e) {
|
||||
$ar = null;
|
||||
}
|
||||
|
||||
if (! $ar) {
|
||||
return redirect('/interviews');
|
||||
}
|
||||
|
||||
try {
|
||||
$artworks = DB::connection('legacy')->table('wallz')
|
||||
->where('uname', $ar->username)
|
||||
->inRandomOrder()
|
||||
->limit(2)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = collect();
|
||||
}
|
||||
|
||||
try {
|
||||
$comments = DB::connection('legacy')->table('interviews_comment as c')
|
||||
->leftJoin('users as u', 'u.uname', '=', 'c.author')
|
||||
->where('c.nid', $id)
|
||||
->select('c.*', 'u.user_id', 'u.user_type', 'u.signature', 'u.icon')
|
||||
->orderBy('c.datum')
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$comments = collect();
|
||||
}
|
||||
|
||||
// compute total posts per author across interviews_comment
|
||||
$authors = $comments->pluck('author')->unique()->values()->all();
|
||||
$postCounts = [];
|
||||
if (!empty($authors)) {
|
||||
try {
|
||||
$counts = DB::connection('legacy')->table('interviews_comment')
|
||||
->select('author', DB::raw('COUNT(*) as cnt'))
|
||||
->whereIn('author', $authors)
|
||||
->groupBy('author')
|
||||
->get();
|
||||
|
||||
foreach ($counts as $c) {
|
||||
$postCounts[$c->author] = $c->cnt;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
$page_title = 'Interview with ' . ($ar->username ?? '');
|
||||
|
||||
return view('legacy.interview', [
|
||||
'ar' => $ar,
|
||||
'artworks' => $artworks,
|
||||
'comments' => $comments,
|
||||
'postCounts' => $postCounts,
|
||||
'page_title' => $page_title,
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/Legacy/InterviewsController.php
Normal file
28
app/Http/Controllers/Legacy/InterviewsController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InterviewsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$interviews = DB::connection('legacy')->table('interviews AS t1')
|
||||
->select('t1.id', 't1.headline', 't2.user_id', 't2.uname', 't2.icon')
|
||||
->leftJoin('users AS t2', 't1.username', '=', 't2.uname')
|
||||
->orderByDesc('t1.datum')
|
||||
->limit(60)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$interviews = collect();
|
||||
}
|
||||
|
||||
$page_title = 'Interviews';
|
||||
|
||||
return view('legacy.interviews', compact('interviews', 'page_title'));
|
||||
}
|
||||
}
|
||||
56
app/Http/Controllers/Legacy/LatestCommentsController.php
Normal file
56
app/Http/Controllers/Legacy/LatestCommentsController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ArtworkComment;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LatestCommentsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hits = 20;
|
||||
|
||||
// Join artwork_comments -> artwork -> user, but only include artworks that are public, approved and published
|
||||
$query = ArtworkComment::with(['user', 'artwork'])
|
||||
->whereHas('artwork', function ($q) {
|
||||
$q->public()->published()->whereNull('deleted_at');
|
||||
})
|
||||
->orderByDesc('created_at');
|
||||
|
||||
$comments = $query->paginate($hits)->withQueryString();
|
||||
|
||||
// Shape results for legacy view
|
||||
$comments->getCollection()->transform(function (ArtworkComment $c) {
|
||||
$art = $c->artwork;
|
||||
$user = $c->user;
|
||||
|
||||
$present = $art ? \App\Services\ThumbnailPresenter::present($art, 'md') : null;
|
||||
$thumb = $present ? ($present['url']) : '/gfx/sb_join.jpg';
|
||||
|
||||
return (object) [
|
||||
'comment_id' => $c->getKey(),
|
||||
'comment_description' => $c->content,
|
||||
'commenter_id' => $c->user_id,
|
||||
'country' => $user->country ?? null,
|
||||
'icon' => $user->avatar ?? null,
|
||||
'uname' => $user->username ?? $user->name ?? 'User',
|
||||
'signature' => $user->signature ?? null,
|
||||
'user_type' => $user->role ?? null,
|
||||
'id' => $art->id ?? null,
|
||||
'name' => $art->title ?? null,
|
||||
'picture' => $art->file_name ?? null,
|
||||
'thumb' => $thumb,
|
||||
'artwork_slug' => $art->slug ?? Str::slug($art->title ?? ''),
|
||||
'datetime' => $c->created_at?->toDateTimeString() ?? now()->toDateTimeString(),
|
||||
];
|
||||
});
|
||||
|
||||
$page_title = 'Latest Comments';
|
||||
|
||||
return view('legacy.latest-comments', compact('page_title', 'comments'));
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/Legacy/LatestController.php
Normal file
51
app/Http/Controllers/Legacy/LatestController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\CursorPaginator;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class LatestController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = 21;
|
||||
|
||||
/** @var CursorPaginator $artworks */
|
||||
$artworks = $this->artworks->browsePublicArtworks($perPage);
|
||||
|
||||
// Shape data for legacy view without legacy tables.
|
||||
$artworks->getCollection()->transform(function (Artwork $artwork) {
|
||||
$primaryCategory = $artwork->categories->sortBy('sort_order')->first();
|
||||
$categoryName = $primaryCategory->name ?? '';
|
||||
$gid = $primaryCategory ? ((int) $primaryCategory->id % 5) * 5 : 0;
|
||||
$present = \App\Services\ThumbnailPresenter::present($artwork, 'md');
|
||||
|
||||
return (object) [
|
||||
'id' => $artwork->id,
|
||||
'name' => $artwork->title,
|
||||
'category_name' => $categoryName,
|
||||
'gid_num' => $gid,
|
||||
'thumb_url' => $present['url'],
|
||||
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
||||
'uname' => $artwork->user->name ?? 'Skinbase',
|
||||
];
|
||||
});
|
||||
|
||||
return view('legacy.latest-artworks', [
|
||||
'artworks' => $artworks,
|
||||
'page_title' => 'Latest Artworks',
|
||||
]);
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/Legacy/MembersController.php
Normal file
51
app/Http/Controllers/Legacy/MembersController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\LegacyService;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MembersController extends Controller
|
||||
{
|
||||
protected LegacyService $legacy;
|
||||
|
||||
public function __construct(LegacyService $legacy)
|
||||
{
|
||||
$this->legacy = $legacy;
|
||||
}
|
||||
|
||||
public function photos(Request $request, $id = null)
|
||||
{
|
||||
$id = (int) ($id ?: 545);
|
||||
|
||||
$result = $this->legacy->categoryPage('', null, $id);
|
||||
if (! $result) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
// categoryPage returns an array with keys used by legacy.browse
|
||||
$page_title = $result['page_title'] ?? ($result['category']->category_name ?? 'Members Photos');
|
||||
$artworks = $result['artworks'] ?? collect();
|
||||
|
||||
// Ensure artworks include `slug`, `thumb`, and `thumb_srcset` properties expected by the legacy view
|
||||
if ($artworks && method_exists($artworks, 'getCollection')) {
|
||||
$artworks->getCollection()->transform(function ($row) {
|
||||
$row->slug = $row->slug ?? Str::slug($row->name ?? '');
|
||||
$row->thumb = $row->thumb ?? ($row->thumb_url ?? null);
|
||||
$row->thumb_srcset = $row->thumb_srcset ?? ($row->thumb_srcset ?? null);
|
||||
return $row;
|
||||
});
|
||||
} elseif (is_iterable($artworks)) {
|
||||
$artworks = collect($artworks)->map(function ($row) {
|
||||
$row->slug = $row->slug ?? Str::slug($row->name ?? '');
|
||||
$row->thumb = $row->thumb ?? ($row->thumb_url ?? null);
|
||||
$row->thumb_srcset = $row->thumb_srcset ?? ($row->thumb_srcset ?? null);
|
||||
return $row;
|
||||
});
|
||||
}
|
||||
|
||||
return view('legacy.browse', compact('page_title', 'artworks'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MonthlyCommentatorsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hits = 30;
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
|
||||
$query = DB::connection('legacy')->table('artworks_comments as t1')
|
||||
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->leftJoin('country as c', 't2.country', '=', 'c.id')
|
||||
->where('t1.user_id', '>', 0)
|
||||
->whereRaw("DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= t1.date")
|
||||
->select(
|
||||
't2.user_id',
|
||||
't2.uname',
|
||||
't2.user_type',
|
||||
't2.country',
|
||||
'c.name as country_name',
|
||||
'c.flag as country_flag',
|
||||
DB::raw('COUNT(*) as num_comments')
|
||||
)
|
||||
->groupBy('t1.user_id')
|
||||
->orderByDesc('num_comments');
|
||||
|
||||
$rows = $query->paginate($hits)->withQueryString();
|
||||
|
||||
$page_title = 'Monthly Top Commentators';
|
||||
|
||||
return view('legacy.monthly-commentators', compact('page_title', 'rows'));
|
||||
}
|
||||
}
|
||||
44
app/Http/Controllers/Legacy/NewsController.php
Normal file
44
app/Http/Controllers/Legacy/NewsController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $slug = null)
|
||||
{
|
||||
$id = (int) $id;
|
||||
|
||||
try {
|
||||
$news = DB::connection('legacy')->table('news as t1')
|
||||
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->where('t1.news_id', $id)
|
||||
->select('t1.*', 't2.uname', 't2.user_type', 't2.signature', 't2.icon')
|
||||
->first();
|
||||
} catch (\Throwable $e) {
|
||||
$news = null;
|
||||
}
|
||||
|
||||
if (empty($news)) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
try {
|
||||
$comments = DB::connection('legacy')->table('news_comment as c')
|
||||
->leftJoin('users as u', 'c.user_id', '=', 'u.user_id')
|
||||
->where('c.news_id', $id)
|
||||
->select('c.posted', 'c.message', 'c.user_id', 'u.user_type', 'u.signature', 'u.icon', 'u.uname')
|
||||
->orderBy('c.posted')
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$comments = collect();
|
||||
}
|
||||
|
||||
$page_title = ($news->headline ?? 'News') . ' - SkinBase News';
|
||||
|
||||
return view('legacy.news', compact('news', 'comments', 'page_title'));
|
||||
}
|
||||
}
|
||||
75
app/Http/Controllers/Legacy/ProfileController.php
Normal file
75
app/Http/Controllers/Legacy/ProfileController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\User;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworkService;
|
||||
|
||||
public function __construct(ArtworkService $artworkService)
|
||||
{
|
||||
$this->artworkService = $artworkService;
|
||||
}
|
||||
|
||||
public function show(Request $request, ?int $id = null, ?string $slug = null)
|
||||
{
|
||||
// Support /profile (current user) and /profile/{id}/{slug}
|
||||
$id = $id ?? (Auth::check() ? Auth::id() : null);
|
||||
|
||||
if (! $id) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$user = User::find($id);
|
||||
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Determine visibility: owner sees all, others only public+approved+published
|
||||
$isOwner = Auth::check() && Auth::id() === $user->id;
|
||||
|
||||
$perPage = 24;
|
||||
|
||||
// Use ArtworkService to fetch artworks for the profile
|
||||
$artworks = $this->artworkService->getArtworksByUser($user->id, $isOwner, $perPage);
|
||||
|
||||
// Shape data for legacy view expectations
|
||||
$artworks->getCollection()->transform(function (Artwork $art) {
|
||||
$present = \App\Services\ThumbnailPresenter::present($art, 'md');
|
||||
|
||||
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',
|
||||
];
|
||||
});
|
||||
|
||||
// Map new User model to legacy view shape expected by templates
|
||||
$legacyUser = (object) [
|
||||
'user_id' => $user->id,
|
||||
'uname' => $user->name,
|
||||
'real_name' => $user->name,
|
||||
'icon' => $user->avatar ?? null,
|
||||
'about_me' => $user->bio ?? null,
|
||||
];
|
||||
|
||||
return view('legacy.profile', [
|
||||
'user' => $legacyUser,
|
||||
'artworks' => $artworks,
|
||||
]);
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/Legacy/TodayDownloadsController.php
Normal file
68
app/Http/Controllers/Legacy/TodayDownloadsController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ArtworkDownload;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TodayDownloadsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hits = 30;
|
||||
|
||||
// Filter downloads created today and join to artworks that are public, approved and published
|
||||
$today = Carbon::now()->toDateString();
|
||||
|
||||
$query = ArtworkDownload::with(['artwork'])
|
||||
->whereDate('created_at', $today)
|
||||
->whereHas('artwork', function ($q) {
|
||||
$q->public()->published()->whereNull('deleted_at');
|
||||
})
|
||||
->selectRaw('artwork_id, COUNT(*) as num_downloads')
|
||||
->groupBy('artwork_id')
|
||||
->orderByDesc('num_downloads');
|
||||
|
||||
$paginator = $query->paginate($hits)->withQueryString();
|
||||
|
||||
// Map to the legacy browse shape
|
||||
$paginator->getCollection()->transform(function ($row) {
|
||||
// $row is a stdClass with artwork_id and num_downloads
|
||||
$art = $row->artwork ?? null;
|
||||
// If Eloquent didn't eager load artwork (group queries sometimes don't), fetch it
|
||||
if (! $art && isset($row->artwork_id)) {
|
||||
$art = \App\Models\Artwork::find($row->artwork_id);
|
||||
}
|
||||
|
||||
$name = $art->title ?? null;
|
||||
$picture = $art->file_name ?? null;
|
||||
$ext = pathinfo($picture ?? '', PATHINFO_EXTENSION) ?: 'jpg';
|
||||
$encoded = null; // legacy encoding unavailable; leave null
|
||||
$present = $art ? \App\Services\ThumbnailPresenter::present($art, 'md') : null;
|
||||
$thumb = $present ? $present['url'] : '/gfx/sb_join.jpg';
|
||||
$categoryId = $art->categories->first()->id ?? null;
|
||||
|
||||
return (object) [
|
||||
'id' => $art->id ?? null,
|
||||
'name' => $name,
|
||||
'picture' => $picture,
|
||||
'slug' => $art->slug ?? Str::slug($name ?? ''),
|
||||
'ext' => $ext,
|
||||
'encoded' => $encoded,
|
||||
'thumb' => $thumb,
|
||||
'thumb_srcset' => $thumb,
|
||||
'category' => $categoryId,
|
||||
'num_downloads' => $row->num_downloads ?? 0,
|
||||
'gid_num' => $categoryId ? ((int) $categoryId % 5) * 5 : 0,
|
||||
];
|
||||
});
|
||||
|
||||
$page_title = 'Today Downloaded Artworks';
|
||||
|
||||
return view('legacy.browse', ['page_title' => $page_title, 'artworks' => $paginator]);
|
||||
}
|
||||
}
|
||||
54
app/Http/Controllers/Legacy/TodayInHistoryController.php
Normal file
54
app/Http/Controllers/Legacy/TodayInHistoryController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TodayInHistoryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hits = 39;
|
||||
|
||||
try {
|
||||
$base = DB::connection('legacy')->table('featured_works as t0')
|
||||
->leftJoin('artworks as t1', 't0.artwork_id', '=', 't1.id')
|
||||
->join('artworks_categories as t2', 't1.category', '=', 't2.category_id')
|
||||
->where('t1.approved', 1)
|
||||
->whereRaw('MONTH(t0.post_date) = MONTH(CURRENT_DATE())')
|
||||
->whereRaw('DAY(t0.post_date) = DAY(CURRENT_DATE())')
|
||||
->select('t1.id', 't1.name', 't1.picture', 't1.uname', 't1.category', 't2.category_name');
|
||||
|
||||
$artworks = $base->orderBy('t0.post_date','desc')->paginate($hits);
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = null;
|
||||
}
|
||||
|
||||
if ($artworks && method_exists($artworks, 'getCollection')) {
|
||||
$artworks->getCollection()->transform(function ($row) {
|
||||
$row->ext = pathinfo($row->picture ?? '', PATHINFO_EXTENSION) ?: 'jpg';
|
||||
$row->encoded = \App\Services\LegacyService::encode($row->id);
|
||||
// Prefer new CDN when artwork exists with hash
|
||||
try {
|
||||
$art = \App\Models\Artwork::find($row->id);
|
||||
$present = \App\Services\ThumbnailPresenter::present($art ?: (array) $row, 'md');
|
||||
$row->thumb_url = $present['url'];
|
||||
$row->thumb_srcset = $present['srcset'];
|
||||
} catch (\Throwable $e) {
|
||||
$present = \App\Services\ThumbnailPresenter::present((array) $row, 'md');
|
||||
$row->thumb_url = $present['url'];
|
||||
$row->thumb_srcset = $present['srcset'];
|
||||
}
|
||||
$row->gid_num = ((int)($row->category ?? 0) % 5) * 5;
|
||||
return $row;
|
||||
});
|
||||
}
|
||||
|
||||
return view('legacy.today-in-history', [
|
||||
'artworks' => $artworks,
|
||||
'page_title' => 'Popular on this day in history',
|
||||
]);
|
||||
}
|
||||
}
|
||||
129
app/Http/Controllers/Legacy/TopAuthorsController.php
Normal file
129
app/Http/Controllers/Legacy/TopAuthorsController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\ArtworkStats;
|
||||
use App\Models\User;
|
||||
|
||||
class TopAuthorsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = 20;
|
||||
$metric = strtolower($request->query('metric', 'views'));
|
||||
|
||||
if (! in_array($metric, ['views', 'downloads'])) {
|
||||
$metric = 'views';
|
||||
}
|
||||
|
||||
// Aggregate artwork_stats grouped by artwork.user_id, filtering only public+approved+published artworks
|
||||
$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)
|
||||
->whereNotNull('artworks.published_at')
|
||||
->where('artworks.published_at', '<=', now())
|
||||
->whereNull('artworks.deleted_at')
|
||||
->selectRaw('artworks.user_id, SUM(artwork_stats.' . $metric . ') as total_metric, MAX(artworks.published_at) as latest_published')
|
||||
->groupBy('artworks.user_id');
|
||||
|
||||
// Join with users to fetch profile info
|
||||
$query = DB::table(DB::raw('(' . $sub->toSql() . ') as t'))
|
||||
->mergeBindings($sub->getQuery())
|
||||
->join('users as u', 'u.id', '=', 't.user_id')
|
||||
->select('u.id as user_id', 'u.name as uname', 'u.username', 't.total_metric', 't.latest_published')
|
||||
->orderByDesc('t.total_metric')
|
||||
->orderByDesc('t.latest_published');
|
||||
|
||||
$authors = $query->paginate($perPage)->withQueryString();
|
||||
|
||||
// Map to legacy view shape
|
||||
$authors->getCollection()->transform(function ($row) use ($metric) {
|
||||
return (object) [
|
||||
'user_id' => $row->user_id,
|
||||
'uname' => $row->uname,
|
||||
'username' => $row->username,
|
||||
'total' => (int) $row->total_metric,
|
||||
'metric' => $metric,
|
||||
];
|
||||
});
|
||||
|
||||
$page_title = 'Top Authors';
|
||||
|
||||
return view('legacy.top-authors', compact('page_title', 'authors', 'metric'));
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TopAuthorsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Top users (most active)
|
||||
try {
|
||||
$topUsers = DB::connection('legacy')->table('wallz as t1')
|
||||
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->select('t2.user_id', 't2.uname', 't2.icon', DB::raw('SUM(t1.dls) AS total_downloads'), DB::raw('COUNT(*) AS uploads'))
|
||||
->groupBy('t1.user_id')
|
||||
->orderByDesc('total_downloads')
|
||||
->limit(23)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$topUsers = collect();
|
||||
}
|
||||
|
||||
// Top followers
|
||||
try {
|
||||
$topFollowers = DB::connection('legacy')->table('friends_list as t1')
|
||||
->rightJoin('users as t2', 't1.friend_id', '=', 't2.user_id')
|
||||
->where('t1.friend_id', '>', 0)
|
||||
->select('t2.uname', 't2.user_id', DB::raw('COUNT(*) as num'))
|
||||
->groupBy('t1.friend_id')
|
||||
->orderByDesc('num')
|
||||
->limit(10)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$topFollowers = collect();
|
||||
}
|
||||
|
||||
// Top commentators
|
||||
try {
|
||||
$topCommentators = DB::connection('legacy')->table('artworks_comments as t1')
|
||||
->join('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->where('t1.user_id', '>', 0)
|
||||
->select('t2.user_id','t2.uname','t2.user_type','t2.country', DB::raw('COUNT(*) as num_comments'))
|
||||
->groupBy('t1.user_id')
|
||||
->orderByDesc('num_comments')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
// enrich with country info if available
|
||||
$topCommentators->transform(function ($c) {
|
||||
if (!empty($c->country)) {
|
||||
$cn = DB::connection('legacy')->table('country')->select('name','flag')->where('id', $c->country)->first();
|
||||
$c->country_name = $cn->name ?? null;
|
||||
$c->country_flag = $cn->flag ?? null;
|
||||
} else {
|
||||
$c->country_name = null;
|
||||
$c->country_flag = null;
|
||||
}
|
||||
return $c;
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
$topCommentators = collect();
|
||||
}
|
||||
|
||||
return view('legacy.top-authors', compact('topUsers', 'topFollowers', 'topCommentators'));
|
||||
}
|
||||
}
|
||||
57
app/Http/Controllers/Legacy/TopFavouritesController.php
Normal file
57
app/Http/Controllers/Legacy/TopFavouritesController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\LegacyService;
|
||||
|
||||
class TopFavouritesController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hits = 21;
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
|
||||
$base = DB::connection('legacy')->table('artworks_favourites as t1')
|
||||
->rightJoin('wallz as t2', 't1.artwork_id', '=', 't2.id')
|
||||
->where('t2.approved', 1)
|
||||
->select('t2.id', 't2.name', 't2.picture', 't2.category', DB::raw('COUNT(*) as num'))
|
||||
->groupBy('t1.artwork_id');
|
||||
|
||||
try {
|
||||
$paginator = (clone $base)->orderBy('num', 'desc')->paginate($hits)->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
$paginator = collect();
|
||||
}
|
||||
|
||||
// Map artworks to include expected properties for legacy card view
|
||||
if ($paginator && method_exists($paginator, 'getCollection')) {
|
||||
$paginator->getCollection()->transform(function ($row) {
|
||||
$row->slug = $row->slug ?? Str::slug($row->name ?? '');
|
||||
$ext = pathinfo($row->picture ?? '', PATHINFO_EXTENSION) ?: 'jpg';
|
||||
$encoded = \App\Helpers\Thumb::encodeId((int) $row->id);
|
||||
$row->encoded = $encoded;
|
||||
$row->ext = $ext;
|
||||
try {
|
||||
$art = \App\Models\Artwork::find($row->id);
|
||||
$present = \App\Services\ThumbnailPresenter::present($art ?: (array) $row, 'md');
|
||||
$row->thumb = $row->thumb ?? $present['url'];
|
||||
$row->thumb_srcset = $row->thumb_srcset ?? ($present['srcset'] ?? $present['url']);
|
||||
} catch (\Throwable $e) {
|
||||
$present = \App\Services\ThumbnailPresenter::present((array) $row, 'md');
|
||||
$row->thumb = $row->thumb ?? $present['url'];
|
||||
$row->thumb_srcset = $row->thumb_srcset ?? ($present['srcset'] ?? $present['url']);
|
||||
}
|
||||
$row->gid_num = ((int)($row->category ?? 0) % 5) * 5;
|
||||
return $row;
|
||||
});
|
||||
}
|
||||
|
||||
$page_title = 'Top Favourites';
|
||||
|
||||
return view('legacy.top-favourites', ['page_title' => $page_title, 'artworks' => $paginator]);
|
||||
}
|
||||
}
|
||||
564
app/Http/Controllers/LegacyController.php
Normal file
564
app/Http/Controllers/LegacyController.php
Normal file
@@ -0,0 +1,564 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LegacyController extends Controller
|
||||
{
|
||||
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';
|
||||
|
||||
[$featured, $memberFeatured] = $this->featured();
|
||||
$latestUploads = $this->latestUploads();
|
||||
$forumNews = $this->forumNews();
|
||||
$ourNews = $this->ourNews();
|
||||
$latestForumActivity = $this->latestForumActivity();
|
||||
|
||||
return view('legacy.home', compact(
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords',
|
||||
'featured',
|
||||
'memberFeatured',
|
||||
'latestUploads',
|
||||
'forumNews',
|
||||
'ourNews',
|
||||
'latestForumActivity'
|
||||
));
|
||||
}
|
||||
|
||||
public function browse(Request $request)
|
||||
{
|
||||
$page_title = 'Browse Uploaded Artworks - Photography, Wallpapers and Skins at SkinBase';
|
||||
$page_meta_description = "Browse Uploaded Photography, Wallpapers and Skins to one of the world's oldest online social community for artists and art enthusiastse.";
|
||||
$page_meta_keywords = 'photography, wallpapers, skins, stock, browse, social, community, artist, picture, photo';
|
||||
|
||||
$perPage = 50;
|
||||
|
||||
try {
|
||||
$artworks = DB::connection('legacy')->table('wallz as w')
|
||||
->leftJoin('artworks_categories as c', 'w.category', '=', 'c.category_id')
|
||||
->leftJoin('users as u', 'w.user_id', '=', 'u.user_id')
|
||||
->select('w.id', 'w.name', 'w.picture', 'w.category', 'w.datum', 'c.category_name', 'u.uname')
|
||||
->where('w.approved', 1)
|
||||
->where('w.public', 'Y')
|
||||
->orderByDesc('w.datum')
|
||||
->paginate($perPage)
|
||||
->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
$placeholder = collect([
|
||||
(object) [
|
||||
'id' => 0,
|
||||
'name' => 'Sample Artwork',
|
||||
'picture' => 'gfx/sb_join.jpg',
|
||||
'category' => null,
|
||||
'datum' => now(),
|
||||
'category_name' => 'Photography',
|
||||
'uname' => 'Skinbase',
|
||||
],
|
||||
]);
|
||||
|
||||
$artworks = new LengthAwarePaginator(
|
||||
$placeholder,
|
||||
$placeholder->count(),
|
||||
$perPage,
|
||||
1,
|
||||
['path' => $request->url(), 'query' => $request->query()]
|
||||
);
|
||||
}
|
||||
|
||||
return view('legacy.browse', compact('page_title', 'page_meta_description', 'page_meta_keywords', 'artworks'));
|
||||
}
|
||||
|
||||
public function category(Request $request, string $group, ?string $slug = null, ?int $id = null)
|
||||
{
|
||||
$group = Str::title($group);
|
||||
$defaults = [
|
||||
'Skins' => 1,
|
||||
'Wallpapers' => 2,
|
||||
'Photography' => 3,
|
||||
'Other' => 4,
|
||||
];
|
||||
|
||||
if (!$id && $slug && ctype_digit($slug)) {
|
||||
$id = (int) $slug;
|
||||
}
|
||||
|
||||
$id = $id ?: ($defaults[$group] ?? null);
|
||||
if (!$id || $id < 1) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
$page_title = $group;
|
||||
$page_meta_description = $group . ' artworks on Skinbase';
|
||||
$page_meta_keywords = strtolower($group) . ', skinbase, artworks, wallpapers, photography, skins';
|
||||
|
||||
try {
|
||||
$category = DB::connection('legacy')->table('artworks_categories')
|
||||
->select('category_id', 'category_name', 'description', 'rootid', 'section_id')
|
||||
->where('category_id', $id)
|
||||
->first();
|
||||
} catch (\Throwable $e) {
|
||||
$category = null;
|
||||
}
|
||||
|
||||
if (!$category) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
$perPage = 40;
|
||||
|
||||
try {
|
||||
$base = DB::connection('legacy')->table('wallz as t1')
|
||||
->select('t1.id', 't1.name', 't1.picture', 't3.uname', 't1.category', 't2.category_name')
|
||||
->join('artworks_categories as t2', 't1.category', '=', 't2.category_id')
|
||||
->leftJoin('users as t3', 't1.user_id', '=', 't3.user_id')
|
||||
->where('t1.approved', 1)
|
||||
->where(function ($q) use ($id, $category) {
|
||||
$q->where('t1.category', (int) $id);
|
||||
if ($category->rootid > 0) {
|
||||
$q->orWhere('t1.rootid', (int) $id);
|
||||
}
|
||||
})
|
||||
->orderByDesc('t1.datum');
|
||||
|
||||
$artworks = $base->paginate($perPage)->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = new LengthAwarePaginator([], 0, $perPage, 1, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$subcategories = DB::connection('legacy')->table('artworks_categories')
|
||||
->select('category_id', 'category_name')
|
||||
->where('rootid', $id)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
|
||||
if ($subcategories->isEmpty() && $category->rootid) {
|
||||
$subcategories = DB::connection('legacy')->table('artworks_categories')
|
||||
->select('category_id', 'category_name')
|
||||
->where('rootid', $category->rootid)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
if ($subcategories->isEmpty()) {
|
||||
$subcategories = DB::connection('legacy')->table('skupine')
|
||||
->select('category_id', 'category_name')
|
||||
->where('rootid', $id)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
try {
|
||||
$subcategories = DB::connection('legacy')->table('skupine')
|
||||
->select('category_id', 'category_name')
|
||||
->where('rootid', $id)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
} catch (\Throwable $e2) {
|
||||
$subcategories = collect();
|
||||
}
|
||||
}
|
||||
|
||||
return view('legacy.category', compact(
|
||||
'group',
|
||||
'category',
|
||||
'artworks',
|
||||
'subcategories',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
|
||||
public function browseCategories()
|
||||
{
|
||||
$page_title = 'Browse Categories';
|
||||
$page_meta_description = 'Browse categories across Photography, Wallpapers, Skins and more on Skinbase.';
|
||||
$page_meta_keywords = 'categories, photography, wallpapers, skins, browse';
|
||||
|
||||
// Load top-level categories (section_id = 0 AND rootid = 0) like the legacy page
|
||||
try {
|
||||
$categories = DB::connection('legacy')->table('artworks_categories')
|
||||
->select('category_id', 'category_name', 'description')
|
||||
->where('section_id', 0)
|
||||
->where('rootid', 0)
|
||||
->orderBy('category_id')
|
||||
->get();
|
||||
|
||||
// Fallback to legacy table name if empty
|
||||
if ($categories->isEmpty()) {
|
||||
$categories = DB::connection('legacy')->table('skupine')
|
||||
->select('category_id', 'category_name', 'description')
|
||||
->where('section_id', 0)
|
||||
->where('rootid', 0)
|
||||
->orderBy('category_id')
|
||||
->get();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
try {
|
||||
$categories = DB::connection('legacy')->table('skupine')
|
||||
->select('category_id', 'category_name', 'description')
|
||||
->where('section_id', 0)
|
||||
->where('rootid', 0)
|
||||
->orderBy('category_id')
|
||||
->get();
|
||||
} catch (\Throwable $e2) {
|
||||
$categories = collect();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all subcategories in one query to avoid N+1 and group them by parent (section_id)
|
||||
$subgroups = collect();
|
||||
if ($categories->isNotEmpty()) {
|
||||
$ids = $categories->pluck('category_id')->unique()->values()->all();
|
||||
try {
|
||||
$subs = DB::connection('legacy')->table('artworks_categories')
|
||||
->select('category_id', 'category_name', 'picture', 'section_id')
|
||||
->whereIn('section_id', $ids)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
|
||||
if ($subs->isEmpty()) {
|
||||
// fallback to skupine table naming
|
||||
$subs = DB::connection('legacy')->table('skupine')
|
||||
->select('category_id', 'category_name', 'picture', 'section_id')
|
||||
->whereIn('section_id', $ids)
|
||||
->orderBy('category_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
$subgroups = $subs->groupBy('section_id');
|
||||
} catch (\Throwable $e) {
|
||||
$subgroups = collect();
|
||||
}
|
||||
}
|
||||
|
||||
return view('legacy.categories', compact(
|
||||
'categories',
|
||||
'subgroups',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
|
||||
public function forumIndex()
|
||||
{
|
||||
$page_title = 'Forum';
|
||||
$page_meta_description = 'Skinbase forum threads.';
|
||||
$page_meta_keywords = 'forum, discussions, topics, skinbase';
|
||||
|
||||
try {
|
||||
$topics = DB::connection('legacy')->table('forum_topics as t')
|
||||
->select(
|
||||
't.topic_id',
|
||||
't.topic',
|
||||
't.discuss',
|
||||
't.last_update',
|
||||
't.privilege',
|
||||
DB::raw('(SELECT COUNT(*) FROM forum_posts p WHERE p.topic_id IN (SELECT topic_id FROM forum_topics st WHERE st.root_id = t.topic_id)) AS num_posts'),
|
||||
DB::raw('(SELECT COUNT(*) FROM forum_topics st WHERE st.root_id = t.topic_id) AS num_subtopics')
|
||||
)
|
||||
->where('t.root_id', 0)
|
||||
->where('t.privilege', '<', 4)
|
||||
->orderByDesc('t.last_update')
|
||||
->limit(100)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$topics = collect();
|
||||
}
|
||||
|
||||
return view('legacy.forum.index', compact(
|
||||
'topics',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
|
||||
public function forumTopic(Request $request, int $topic_id)
|
||||
{
|
||||
try {
|
||||
$topic = DB::connection('legacy')->table('forum_topics')->where('topic_id', $topic_id)->first();
|
||||
} catch (\Throwable $e) {
|
||||
$topic = null;
|
||||
}
|
||||
|
||||
if (!$topic) {
|
||||
return redirect('/forum');
|
||||
}
|
||||
|
||||
$page_title = $topic->topic;
|
||||
$page_meta_description = Str::limit(strip_tags($topic->discuss ?? 'Forum topic'), 160);
|
||||
$page_meta_keywords = 'forum, topic, skinbase';
|
||||
|
||||
// Fetch subtopics; if none exist, fall back to posts (matches legacy behavior where some topics hold posts directly)
|
||||
try {
|
||||
$subtopics = DB::connection('legacy')->table('forum_topics as t')
|
||||
->leftJoin('users as u', 't.user_id', '=', 'u.user_id')
|
||||
->select(
|
||||
't.topic_id',
|
||||
't.topic',
|
||||
't.discuss',
|
||||
't.post_date',
|
||||
't.last_update',
|
||||
'u.uname',
|
||||
DB::raw('(SELECT COUNT(*) FROM forum_posts p WHERE p.topic_id = t.topic_id) AS num_posts')
|
||||
)
|
||||
->where('t.root_id', $topic->topic_id)
|
||||
->orderByDesc('t.last_update')
|
||||
->paginate(50)
|
||||
->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
$subtopics = new LengthAwarePaginator([], 0, 50, 1, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($subtopics->total() > 0) {
|
||||
return view('legacy.forum.topic', compact(
|
||||
'topic',
|
||||
'subtopics',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
|
||||
$sort = strtolower($request->query('sort', 'desc')) === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
// First try topic_id; if empty, retry using legacy tid column
|
||||
$posts = new LengthAwarePaginator([], 0, 50, 1, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]);
|
||||
|
||||
try {
|
||||
$posts = DB::connection('legacy')->table('forum_posts as p')
|
||||
->leftJoin('users as u', 'p.user_id', '=', 'u.user_id')
|
||||
->select('p.id', 'p.message', 'p.post_date', 'u.uname', 'u.user_id', 'u.icon', 'u.eicon')
|
||||
->where('p.topic_id', $topic->topic_id)
|
||||
->orderBy('p.post_date', $sort)
|
||||
->paginate(50)
|
||||
->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
// will retry with tid
|
||||
}
|
||||
|
||||
if ($posts->total() === 0) {
|
||||
try {
|
||||
$posts = DB::connection('legacy')->table('forum_posts as p')
|
||||
->leftJoin('users as u', 'p.user_id', '=', 'u.user_id')
|
||||
->select('p.id', 'p.message', 'p.post_date', 'u.uname', 'u.user_id', 'u.icon', 'u.eicon')
|
||||
->where('p.tid', $topic->topic_id)
|
||||
->orderBy('p.post_date', $sort)
|
||||
->paginate(50)
|
||||
->withQueryString();
|
||||
} catch (\Throwable $e) {
|
||||
// keep empty paginator
|
||||
}
|
||||
}
|
||||
|
||||
return view('legacy.forum.posts', compact(
|
||||
'topic',
|
||||
'posts',
|
||||
'page_title',
|
||||
'page_meta_description',
|
||||
'page_meta_keywords'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch featured artworks with graceful fallbacks.
|
||||
*/
|
||||
private function featured(): array
|
||||
{
|
||||
$featured = null;
|
||||
$memberFeatured = null;
|
||||
|
||||
try {
|
||||
$featured = DB::connection('legacy')->table('featured_works as fw')
|
||||
->leftJoin('wallz as w', 'fw.artwork_id', '=', 'w.id')
|
||||
->leftJoin('users as u', 'w.user_id', '=', 'u.user_id')
|
||||
->select('w.id', 'w.name', 'w.picture', 'u.uname', 'fw.post_date')
|
||||
->orderByDesc('fw.post_date')
|
||||
->first();
|
||||
|
||||
$memberFeatured = DB::connection('legacy')->table('users_opinions as o')
|
||||
->leftJoin('wallz as w', 'o.artwork_id', '=', 'w.id')
|
||||
->leftJoin('users as u', 'w.user_id', '=', 'u.user_id')
|
||||
->select(DB::raw('COUNT(*) AS votes'), 'w.id', 'w.name', 'w.picture', 'u.uname')
|
||||
->whereRaw('o.post_date > SUBDATE(CURRENT_DATE(), INTERVAL 30 DAY)')
|
||||
->where('o.score', 4)
|
||||
->groupBy('o.artwork_id', 'w.id', 'w.name', 'w.picture', 'u.uname')
|
||||
->orderByDesc('votes')
|
||||
->limit(1)
|
||||
->first();
|
||||
} catch (\Throwable $e) {
|
||||
// Fail soft; render placeholders
|
||||
}
|
||||
|
||||
if (!$featured) {
|
||||
$featured = (object) [
|
||||
'id' => 0,
|
||||
'name' => 'Featured Artwork',
|
||||
'picture' => '/gfx/sb_join.jpg',
|
||||
'uname' => 'Skinbase',
|
||||
];
|
||||
}
|
||||
|
||||
if (!$memberFeatured) {
|
||||
$memberFeatured = (object) [
|
||||
'id' => 0,
|
||||
'name' => 'Members Pick',
|
||||
'picture' => '/gfx/sb_join.jpg',
|
||||
'uname' => 'Skinbase',
|
||||
'votes' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
return [$featured, $memberFeatured];
|
||||
}
|
||||
|
||||
private function forumNews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection('legacy')->table('forum_topics as t1')
|
||||
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
|
||||
->select(
|
||||
't1.topic_id',
|
||||
't1.topic',
|
||||
't1.views',
|
||||
't1.post_date',
|
||||
't1.preview',
|
||||
't2.uname'
|
||||
)
|
||||
->where('t1.root_id', 2876)
|
||||
->where('t1.privilege', '<', 4)
|
||||
->orderByDesc('t1.post_date')
|
||||
->limit(8)
|
||||
->get()
|
||||
->toArray();
|
||||
} catch (\Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function ourNews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection('legacy')->table('news as t1')
|
||||
->join('news_categories as t2', 't1.category_id', '=', 't2.category_id')
|
||||
->join('users as t3', 't1.user_id', '=', 't3.user_id')
|
||||
->select(
|
||||
't1.news_id',
|
||||
't1.headline',
|
||||
't1.picture',
|
||||
't1.preview',
|
||||
't1.create_date',
|
||||
't1.views',
|
||||
't2.category_name',
|
||||
't3.uname',
|
||||
DB::raw('(SELECT COUNT(*) FROM news_comment WHERE news_id = t1.news_id) AS num_comments')
|
||||
)
|
||||
->orderByDesc('t1.create_date')
|
||||
->limit(5)
|
||||
->get()
|
||||
->toArray();
|
||||
} catch (\Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function latestForumActivity(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection('legacy')->table('forum_topics as t1')
|
||||
->select(
|
||||
't1.topic_id',
|
||||
't1.topic',
|
||||
DB::raw('(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)
|
||||
->orderByDesc('t1.last_update')
|
||||
->orderByDesc('t1.post_date')
|
||||
->limit(10)
|
||||
->get()
|
||||
->toArray();
|
||||
} catch (\Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load latest uploads either from cached JSON or DB.
|
||||
*/
|
||||
private function latestUploads(): array
|
||||
{
|
||||
$uploads = [];
|
||||
|
||||
// Try cache file first
|
||||
$cachePath = base_path('oldSite/www/cache/latest_uploads.json');
|
||||
if (File::exists($cachePath)) {
|
||||
$json = File::get($cachePath);
|
||||
$uploads = json_decode($json, true) ?: [];
|
||||
}
|
||||
|
||||
// Fallback to DB if cache missing
|
||||
if (empty($uploads)) {
|
||||
try {
|
||||
$uploads = DB::connection('legacy')->table('wallz as w')
|
||||
->leftJoin('users as u', 'w.user_id', '=', 'u.user_id')
|
||||
->leftJoin('artworks_categories as c', 'w.category', '=', 'c.category_id')
|
||||
->where('w.approved', 1)
|
||||
->orderByDesc('w.datum')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
return [
|
||||
'id' => $row->id,
|
||||
'name' => $row->name,
|
||||
'picture' => $row->picture,
|
||||
'uname' => $row->uname,
|
||||
'category_name' => $row->category_name ?? '',
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
} catch (\Throwable $e) {
|
||||
// Soft fail
|
||||
$uploads = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback placeholders
|
||||
if (empty($uploads)) {
|
||||
$uploads = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Sample Artwork',
|
||||
'picture' => 'gfx/sb_join.jpg',
|
||||
'uname' => 'Skinbase',
|
||||
'category_name' => 'Photography',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $uploads;
|
||||
}
|
||||
}
|
||||
114
app/Http/Controllers/ManageController.php
Normal file
114
app/Http/Controllers/ManageController.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Models\ArtworkCategory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManageController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$userId = $request->user()->id;
|
||||
$perPage = 50;
|
||||
|
||||
// Use legacy connection query builder and join category name to avoid Eloquent model issues
|
||||
$query = DB::connection('legacy')->table('artworks as a')
|
||||
->leftJoin('artworks_categories as c', 'a.category', '=', 'c.category_id')
|
||||
->where('a.user_id', $userId)
|
||||
->select('a.*', 'c.category_name')
|
||||
->orderByDesc('a.datum')
|
||||
->orderByDesc('a.id');
|
||||
|
||||
$artworks = $query->paginate($perPage);
|
||||
|
||||
return view('manage.index', [
|
||||
'artworks' => $artworks,
|
||||
'page_title' => 'Artwork Manager',
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$userId = $request->user()->id;
|
||||
$artwork = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
|
||||
if (! $artwork) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$categories = DB::connection('legacy')->table('artworks_categories')->where('section_id', 0)->orderBy('category_id')->get();
|
||||
|
||||
return view('manage.edit', [
|
||||
'artwork' => $artwork,
|
||||
'categories' => $categories,
|
||||
'page_title' => 'Edit Artwork: ' . ($artwork->name ?? ''),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$userId = $request->user()->id;
|
||||
$existing = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
|
||||
|
||||
if (! $existing) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'section' => 'nullable|integer',
|
||||
'description' => 'nullable|string',
|
||||
'artwork' => 'nullable|file|image',
|
||||
'attachment' => 'nullable|file',
|
||||
]);
|
||||
$update = [
|
||||
'name' => $data['name'],
|
||||
'category' => $data['section'] ?? $existing->category,
|
||||
'description' => $data['description'] ?? $existing->description,
|
||||
'updated' => now(),
|
||||
];
|
||||
|
||||
// handle artwork image upload (replacing picture)
|
||||
if ($request->hasFile('artwork')) {
|
||||
$file = $request->file('artwork');
|
||||
$path = $file->store('public/uploads/artworks');
|
||||
$filename = basename($path);
|
||||
$update['picture'] = $filename;
|
||||
}
|
||||
|
||||
// handle attachment upload (zip, etc.)
|
||||
if ($request->hasFile('attachment')) {
|
||||
$att = $request->file('attachment');
|
||||
$attPath = $att->store('public/uploads/attachments');
|
||||
$update['fname'] = basename($attPath);
|
||||
}
|
||||
|
||||
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->update($update);
|
||||
|
||||
return redirect()->route('manage')->with('status', 'Artwork was successfully updated.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id)
|
||||
{
|
||||
$userId = $request->user()->id;
|
||||
$artwork = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
|
||||
if (! $artwork) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// delete files if present (stored in new storage location)
|
||||
if (!empty($artwork->fname)) {
|
||||
Storage::delete('public/uploads/attachments/' . $artwork->fname);
|
||||
}
|
||||
if (!empty($artwork->picture)) {
|
||||
Storage::delete('public/uploads/artworks/' . $artwork->picture);
|
||||
}
|
||||
|
||||
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->delete();
|
||||
|
||||
return redirect()->route('manage')->with('status', 'Artwork deleted.');
|
||||
}
|
||||
}
|
||||
61
app/Http/Controllers/ProfileController.php
Normal file
61
app/Http/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
// Soft-delete the user (preserve record) — align with soft-delete policy.
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
58
app/Http/Controllers/Web/ArtworkController.php
Normal file
58
app/Http/Controllers/Web/ArtworkController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ArtworkController extends Controller
|
||||
{
|
||||
protected ArtworkService $service;
|
||||
|
||||
public function __construct(ArtworkService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse artworks for a category (Blade view).
|
||||
*/
|
||||
public function category(Request $request, Category $category): View
|
||||
{
|
||||
$perPage = (int) $request->get('per_page', 24);
|
||||
|
||||
$artworks = $this->service->getCategoryArtworks($category, $perPage);
|
||||
|
||||
return view('artworks.index', [
|
||||
'artworks' => $artworks,
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show single artwork page by slug (Blade view).
|
||||
*/
|
||||
public function show(string $slug): View
|
||||
{
|
||||
try {
|
||||
$artwork = $this->service->getPublicArtworkBySlug($slug);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Prepare simple SEO meta data for Blade; keep controller thin.
|
||||
$meta = [
|
||||
'title' => $artwork->title,
|
||||
'description' => str(config($artwork->description ?? ''))->limit(160),
|
||||
'canonical' => $artwork->canonical_url ?? null,
|
||||
];
|
||||
|
||||
return view('artworks.show', [
|
||||
'artwork' => $artwork,
|
||||
'meta' => $meta,
|
||||
]);
|
||||
}
|
||||
}
|
||||
21
app/Http/Requests/ArtworkIndexRequest.php
Normal file
21
app/Http/Requests/ArtworkIndexRequest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ArtworkIndexRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'per_page' => 'nullable|integer|min:1|max:100',
|
||||
'sort' => 'nullable|in:latest,oldest',
|
||||
'q' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Http/Requests/Auth/LoginRequest.php
Normal file
85
app/Http/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/ProfileUpdateRequest.php
Normal file
30
app/Http/Requests/ProfileUpdateRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
81
app/Http/Resources/ArtworkListResource.php
Normal file
81
app/Http/Resources/ArtworkListResource.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\Resources\MissingValue;
|
||||
|
||||
class ArtworkListResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array for listings (browse feed).
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
if ($this instanceof MissingValue || $this->resource instanceof MissingValue) {
|
||||
return [];
|
||||
}
|
||||
// Safe accessor to avoid magic __get which may trigger MissingValue errors
|
||||
$get = function ($key) {
|
||||
$r = $this->resource;
|
||||
if ($r instanceof MissingValue || $r === null) {
|
||||
return null;
|
||||
}
|
||||
if (method_exists($r, 'getAttribute')) {
|
||||
return $r->getAttribute($key);
|
||||
}
|
||||
if (is_array($r)) {
|
||||
return $r[$key] ?? null;
|
||||
}
|
||||
if (is_object($r)) {
|
||||
return $r->{$key} ?? null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
$primaryCategory = $this->whenLoaded('categories', function () {
|
||||
return $this->categories->sortBy('sort_order')->first();
|
||||
});
|
||||
|
||||
// Normalize MissingValue into null so later checks are straightforward
|
||||
if ($primaryCategory instanceof MissingValue) {
|
||||
$primaryCategory = null;
|
||||
}
|
||||
|
||||
$contentTypeSlug = null;
|
||||
$categoryPath = null;
|
||||
if ($primaryCategory) {
|
||||
$contentTypeSlug = optional($primaryCategory->contentType)->slug ?? null;
|
||||
$categoryPath = $primaryCategory->full_slug_path ?? null;
|
||||
}
|
||||
$slugVal = $get('slug');
|
||||
$webUrl = $contentTypeSlug && $categoryPath && $slugVal
|
||||
? '/' . strtolower($contentTypeSlug) . '/' . strtolower($categoryPath) . '/' . $slugVal
|
||||
: null;
|
||||
|
||||
return [
|
||||
'slug' => $slugVal,
|
||||
'title' => $get('title'),
|
||||
'description' => $this->when($request->boolean('include_description'), fn() => $get('description')),
|
||||
'dimensions' => [
|
||||
'width' => $get('width'),
|
||||
'height' => $get('height'),
|
||||
],
|
||||
'thumbnail_url' => $this->when(! empty($get('file_path')), fn() => Storage::url($get('file_path'))),
|
||||
'author' => $this->whenLoaded('user', function () {
|
||||
return [
|
||||
'name' => $this->user->name ?? null,
|
||||
];
|
||||
}),
|
||||
'category' => $primaryCategory ? [
|
||||
'slug' => $primaryCategory->slug ?? null,
|
||||
'name' => $primaryCategory->name ?? null,
|
||||
'content_type' => $contentTypeSlug,
|
||||
'url' => $webUrl,
|
||||
] : null,
|
||||
'urls' => [
|
||||
'web' => $webUrl,
|
||||
'canonical' => $webUrl,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
64
app/Http/Resources/ArtworkResource.php
Normal file
64
app/Http/Resources/ArtworkResource.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\Resources\MissingValue;
|
||||
|
||||
class ArtworkResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
if ($this instanceof MissingValue || $this->resource instanceof MissingValue) {
|
||||
return [];
|
||||
}
|
||||
$get = function ($key) {
|
||||
$r = $this->resource;
|
||||
if ($r instanceof MissingValue || $r === null) {
|
||||
return null;
|
||||
}
|
||||
// Eloquent model: prefer getAttribute to avoid magic proxies
|
||||
if (method_exists($r, 'getAttribute')) {
|
||||
return $r->getAttribute($key);
|
||||
}
|
||||
if (is_array($r)) {
|
||||
return $r[$key] ?? null;
|
||||
}
|
||||
if (is_object($r)) {
|
||||
return $r->{$key} ?? null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return [
|
||||
'slug' => $get('slug'),
|
||||
'title' => $get('title'),
|
||||
'description' => $get('description'),
|
||||
'width' => $get('width'),
|
||||
'height' => $get('height'),
|
||||
|
||||
// File URLs: produce public URLs without exposing internal file_path
|
||||
'file' => [
|
||||
'name' => $get('file_name') ?? null,
|
||||
'url' => $this->when(! empty($get('file_path')), fn() => Storage::url($get('file_path'))),
|
||||
'size' => $get('file_size') ?? null,
|
||||
'mime_type' => $get('mime_type') ?? null,
|
||||
],
|
||||
|
||||
'categories' => $this->whenLoaded('categories', function () {
|
||||
return $this->categories->map(fn($c) => [
|
||||
'slug' => $c->slug ?? null,
|
||||
'name' => $c->name ?? null,
|
||||
])->values();
|
||||
}),
|
||||
|
||||
'published_at' => $this->whenNotNull($get('published_at') ? $this->published_at->toAtomString() : null),
|
||||
|
||||
'urls' => [
|
||||
'canonical' => $get('canonical_url') ?? null,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user