Save workspace changes
This commit is contained in:
@@ -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 {
|
||||
DB::table('artwork_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 = DB::table('artwork_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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AvatarUrl;
|
||||
|
||||
class AvatarController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $name = null)
|
||||
{
|
||||
$userId = (int) $id;
|
||||
$target = AvatarUrl::forUser($userId, null, 128);
|
||||
|
||||
return redirect()->away($target, 301);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\ContentType;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\CursorPaginator;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
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);
|
||||
$sort = (string) $request->get('sort', 'latest');
|
||||
|
||||
// Canonical browse routes are slug-based (/photography, /wallpapers, /skins, /other, /{type}/{path}).
|
||||
// Prevent duplicate query-driven browse URLs.
|
||||
$legacyCategory = trim((string) $request->query('category', ''), '/');
|
||||
if ($legacyCategory !== '') {
|
||||
return redirect('/' . strtolower($legacyCategory), 301);
|
||||
}
|
||||
$legacyContentType = trim((string) $request->query('content_type', ''), '/');
|
||||
if ($legacyContentType !== '') {
|
||||
return redirect('/' . strtolower($legacyContentType), 301);
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var CursorPaginator $artworks */
|
||||
$artworks = $this->artworks->browsePublicArtworks($perPage, $sort);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (count($artworks) === 0) {
|
||||
Log::warning('browse.missing_artworks', [
|
||||
'url' => $request->fullUrl(),
|
||||
]);
|
||||
abort(410);
|
||||
}
|
||||
|
||||
// Shape data for the legacy Blade while using authoritative tables only.
|
||||
$artworks->getCollection()->transform(fn (Artwork $artwork) => $this->mapArtwork($artwork));
|
||||
|
||||
$rootCategories = ContentType::ordered()
|
||||
->get(['name', 'slug'])
|
||||
->map(fn (ContentType $type) => (object) [
|
||||
'name' => $type->name,
|
||||
'url' => '/' . strtolower($type->slug),
|
||||
]);
|
||||
|
||||
$page_canonical = url('/browse');
|
||||
|
||||
return view('legacy::browse', compact('page_title', 'page_meta_description', 'page_meta_keywords', 'page_canonical', 'artworks', 'rootCategories'));
|
||||
}
|
||||
|
||||
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 ?? '#',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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);
|
||||
$sort = (string) $request->get('sort', 'latest');
|
||||
|
||||
try {
|
||||
$artworks = $this->artworkService->getArtworksByCategoryPath($slugs, $perPage, $sort);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoryRedirectController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, string $group, ?string $slug = null, ?string $id = null): RedirectResponse
|
||||
{
|
||||
$groupSlug = strtolower(trim($group, '/'));
|
||||
$slugPart = strtolower(trim((string) $slug, '/'));
|
||||
|
||||
$category = $this->resolveCategory($groupSlug, $slugPart, $id);
|
||||
|
||||
if ($category && $category->contentType) {
|
||||
$target = $category->url;
|
||||
|
||||
if ($request->getQueryString()) {
|
||||
$target .= '?' . $request->getQueryString();
|
||||
}
|
||||
|
||||
return redirect()->to($target, 301);
|
||||
}
|
||||
|
||||
return redirect()->route('categories.index', $request->query(), 301);
|
||||
}
|
||||
|
||||
private function resolveCategory(string $groupSlug, string $slugPart, ?string $id): ?Category
|
||||
{
|
||||
if ($id !== null && ctype_digit((string) $id)) {
|
||||
$category = Category::query()
|
||||
->with('contentType')
|
||||
->find((int) $id);
|
||||
|
||||
if ($category) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
if ($slugPart !== '') {
|
||||
$category = Category::query()
|
||||
->with('contentType')
|
||||
->where('slug', $slugPart)
|
||||
->whereHas('parent', fn ($query) => $query->where('slug', $groupSlug))
|
||||
->first();
|
||||
|
||||
if ($category) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
return Category::query()
|
||||
->with('contentType')
|
||||
->where('slug', $groupSlug)
|
||||
->whereNull('parent_id')
|
||||
->first();
|
||||
}
|
||||
}
|
||||
@@ -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::table('smileys')->select('code', 'picture', 'emotion')->get();
|
||||
} catch (\Throwable $e) {
|
||||
$smileys = collect();
|
||||
}
|
||||
|
||||
return view('legacy::chat', compact('page_title', 'adHtml', 'chatHtml', 'smileys'));
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\UserFavorite;
|
||||
|
||||
class FavouritesController extends Controller
|
||||
{
|
||||
public function index(Request $request, $userId = null, $username = null)
|
||||
{
|
||||
$userId = $userId ? (int)$userId : ($request->user()->id ?? null);
|
||||
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
$hits = 20;
|
||||
$start = ($page - 1) * $hits;
|
||||
|
||||
$total = 0;
|
||||
$results = collect();
|
||||
|
||||
// Prefer Eloquent model if table exists
|
||||
try {
|
||||
$schema = DB::getSchemaBuilder();
|
||||
} catch (\Throwable $e) {
|
||||
$schema = null;
|
||||
}
|
||||
|
||||
// Detect user id and name columns for compatibility with legacy schema
|
||||
$userIdCol = Schema::hasColumn('users', 'user_id') ? 'user_id' : 'id';
|
||||
$userNameCol = null;
|
||||
foreach (['uname', 'username', 'name'] as $col) {
|
||||
if (Schema::hasColumn('users', $col)) {
|
||||
$userNameCol = $col;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($schema && $schema->hasTable('user_favorites') && class_exists(UserFavorite::class)) {
|
||||
try {
|
||||
$query = UserFavorite::with(['artwork.user'])
|
||||
->where('user_id', $userId)
|
||||
->orderByDesc('created_at')
|
||||
->orderByDesc('artwork_id');
|
||||
|
||||
$total = (int) $query->count();
|
||||
|
||||
$favorites = $query->skip($start)->take($hits)->get();
|
||||
|
||||
$results = $favorites->map(function ($fav) use ($userNameCol) {
|
||||
$art = $fav->artwork;
|
||||
if (! $art) {
|
||||
return null;
|
||||
}
|
||||
$item = (object) $art->toArray();
|
||||
$item->uname = ($userNameCol && isset($art->user)) ? ($art->user->{$userNameCol} ?? null) : null;
|
||||
$item->datum = $fav->created_at;
|
||||
return $item;
|
||||
})->filter();
|
||||
} catch (\Throwable $e) {
|
||||
$total = 0;
|
||||
$results = collect();
|
||||
}
|
||||
} else {
|
||||
// Fallback to legacy tables
|
||||
try {
|
||||
if ($schema && $schema->hasTable('artworks_favourites')) {
|
||||
$favTable = 'artworks_favourites';
|
||||
} elseif ($schema && $schema->hasTable('favourites')) {
|
||||
$favTable = 'favourites';
|
||||
} else {
|
||||
$favTable = null;
|
||||
}
|
||||
|
||||
if ($schema && $schema->hasTable('artworks')) {
|
||||
$artTable = 'artworks';
|
||||
} elseif ($schema && $schema->hasTable('wallz')) {
|
||||
$artTable = 'wallz';
|
||||
} else {
|
||||
$artTable = null;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$favTable = null;
|
||||
$artTable = null;
|
||||
}
|
||||
|
||||
if ($favTable && $artTable) {
|
||||
try {
|
||||
$total = (int) DB::table($favTable)->where('user_id', $userId)->count();
|
||||
|
||||
$t2JoinCol = 't2.' . $userIdCol;
|
||||
$t2NameSelect = $userNameCol ? DB::raw("t2.{$userNameCol} as uname") : DB::raw("'' as uname");
|
||||
|
||||
$results = DB::table($favTable . ' as t1')
|
||||
->rightJoin($artTable . ' as t3', 't1.artwork_id', '=', 't3.id')
|
||||
->leftJoin('users as t2', 't3.user_id', '=', $t2JoinCol)
|
||||
->where('t1.user_id', $userId)
|
||||
->select('t3.*', $t2NameSelect, 't1.datum')
|
||||
->orderByDesc('t1.datum')
|
||||
->orderByDesc('t1.artwork_id')
|
||||
->skip($start)
|
||||
->take($hits)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$total = 0;
|
||||
$results = collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = collect($results)->filter()->values()->transform(function ($row) {
|
||||
$row->name = $row->name ?? '';
|
||||
$row->slug = $row->slug ?? Str::slug($row->name);
|
||||
$row->encoded = isset($row->id) ? app(\App\Helpers\Thumb::class)::encodeId((int)$row->id) : null;
|
||||
return $row;
|
||||
});
|
||||
|
||||
$page_title = ($username ?: ($userNameCol ? DB::table('users')->where($userIdCol, $userId)->value($userNameCol) : '')) . ' Favourites';
|
||||
|
||||
return view('legacy::favourites', [
|
||||
'results' => $results,
|
||||
'page_title' => $page_title,
|
||||
'user_id' => $userId,
|
||||
'page' => $page,
|
||||
'hits' => $hits,
|
||||
'total' => $total,
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $userId, $artworkId)
|
||||
{
|
||||
$auth = $request->user();
|
||||
if (! $auth || $auth->id != (int)$userId) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$favTable = Schema::hasTable('user_favorites') ? 'user_favorites' : (Schema::hasTable('artworks_favourites') ? 'artworks_favourites' : 'favourites');
|
||||
|
||||
DB::table($favTable)->where('user_id', (int)$userId)->where('artwork_id', (int)$artworkId)->delete();
|
||||
|
||||
return redirect()->route('legacy.favourites', ['id' => $userId])->with('status', 'Removed from favourites');
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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::table('interviews_comment')->insert([
|
||||
'nid' => $interviewId,
|
||||
'author' => $_SESSION['web_login']['username'] ?? 'Anonymous',
|
||||
'datum' => DB::raw('CURRENT_TIMESTAMP'),
|
||||
'tekst' => $tekst,
|
||||
]);
|
||||
|
||||
$ar2 = DB::table('users')
|
||||
->where('uname', $_SESSION['web_login']['username'])
|
||||
->first();
|
||||
|
||||
if (!empty($ar2->user_id)) {
|
||||
DB::table('users_statistics')
|
||||
->where('user_id', $ar2->user_id)
|
||||
->increment('newscomment');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// fail silently
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$ar = DB::table('interviews')->where('id', $id)->first();
|
||||
} catch (\Throwable $e) {
|
||||
$ar = null;
|
||||
}
|
||||
|
||||
if (! $ar) {
|
||||
return redirect('/interviews');
|
||||
}
|
||||
|
||||
try {
|
||||
$artworks = DB::table('wallz')
|
||||
->where('uname', $ar->username)
|
||||
->inRandomOrder()
|
||||
->limit(2)
|
||||
->get();
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = collect();
|
||||
}
|
||||
|
||||
try {
|
||||
$comments = DB::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::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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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::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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
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']) : 'https://files.skinbase.org/default/missing_md.webp';
|
||||
|
||||
return (object) [
|
||||
'comment_id' => $c->getKey(),
|
||||
'comment_description' => $c->content,
|
||||
'commenter_id' => $c->user_id,
|
||||
'country' => $user->country ?? null,
|
||||
'icon' => $user ? DB::table('user_profiles')->where('user_id', $user->id)->value('avatar_hash') : 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'));
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MembersController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function photos(Request $request, $id = null)
|
||||
{
|
||||
$artworks = $this->artworks->getArtworksByContentType('photography', 40);
|
||||
|
||||
$artworks->getCollection()->load([
|
||||
'user:id,name,username',
|
||||
'user.profile:user_id,avatar_hash',
|
||||
]);
|
||||
|
||||
$artworks->getCollection()->transform(function (Artwork $artwork) {
|
||||
$primaryCategory = $artwork->categories->sortBy('sort_order')->first();
|
||||
$present = \App\Services\ThumbnailPresenter::present($artwork, 'md');
|
||||
|
||||
return (object) [
|
||||
'id' => $artwork->id,
|
||||
'name' => $artwork->title,
|
||||
'slug' => $artwork->slug,
|
||||
'url' => '/art/' . $artwork->id . '/' . $artwork->slug,
|
||||
'thumb' => $present['url'],
|
||||
'thumb_url' => $present['url'],
|
||||
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
||||
'uname' => $artwork->user->name ?? 'Skinbase',
|
||||
'username' => $artwork->user->username ?? '',
|
||||
'avatar_url' => \App\Support\AvatarUrl::forUser((int) ($artwork->user->id ?? 0), $artwork->user->profile->avatar_hash ?? null, 64),
|
||||
'content_type_name' => $primaryCategory?->contentType?->name ?? 'Photography',
|
||||
'content_type_slug' => $primaryCategory?->contentType?->slug ?? 'photography',
|
||||
'category_name' => $primaryCategory?->name ?? '',
|
||||
'category_slug' => $primaryCategory?->slug ?? '',
|
||||
'width' => $artwork->width,
|
||||
'height' => $artwork->height,
|
||||
'published_at' => $artwork->published_at,
|
||||
];
|
||||
});
|
||||
|
||||
$page_title = 'Member Photos';
|
||||
|
||||
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::table('artwork_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'));
|
||||
}
|
||||
}
|
||||
@@ -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::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::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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Services\ContentTypes\ContentTypeSlugResolver;
|
||||
|
||||
class PhotographyController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(
|
||||
ArtworkService $artworks,
|
||||
private readonly ContentTypeSlugResolver $contentTypeResolver,
|
||||
)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$segment = strtolower($request->segment(1) ?? 'photography');
|
||||
$resolution = $this->contentTypeResolver->resolve($segment);
|
||||
|
||||
if (! $resolution->found() || $resolution->contentType === null) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$contentType = $resolution->contentType;
|
||||
$contentSlug = strtolower((string) $contentType->slug);
|
||||
|
||||
if ($resolution->requiresRedirect()) {
|
||||
$target = url('/' . $contentSlug);
|
||||
|
||||
if ($request->getQueryString()) {
|
||||
$target .= '?' . $request->getQueryString();
|
||||
}
|
||||
|
||||
return redirect()->to($target, 301);
|
||||
}
|
||||
|
||||
$id = null;
|
||||
if ($contentSlug === 'photography') {
|
||||
$id = 3;
|
||||
}
|
||||
|
||||
// Fetch legacy category info if available (only when we have an id)
|
||||
$category = null;
|
||||
try {
|
||||
if ($id !== null && Schema::hasTable('artworks_categories')) {
|
||||
$category = DB::table('artworks_categories')
|
||||
->select('category_name', 'rootid', 'section_id', 'description', 'category_id')
|
||||
->where('category_id', $id)
|
||||
->first();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$category = null;
|
||||
}
|
||||
|
||||
$page_title = $category->category_name ?? ($contentType->name ?? ucfirst($contentSlug));
|
||||
$tidy = $category->description ?? ($contentType->description ?? null);
|
||||
|
||||
$perPage = 40;
|
||||
$sort = (string) $request->get('sort', 'latest');
|
||||
|
||||
try {
|
||||
$artworks = $this->artworks->getArtworksByContentType($contentSlug, $perPage, $sort);
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = new \Illuminate\Pagination\LengthAwarePaginator([], 0, $perPage, 1, [
|
||||
'path' => url()->current(),
|
||||
]);
|
||||
}
|
||||
|
||||
$subcategories = collect();
|
||||
try {
|
||||
if ($id !== null && Schema::hasTable('artworks_categories')) {
|
||||
$subcategories = DB::table('artworks_categories')->select('category_id','category_name')->where('rootid', $id)->orderBy('category_name')->get();
|
||||
if ($subcategories->count() == 0 && !empty($category->rootid)) {
|
||||
$subcategories = DB::table('artworks_categories')->select('category_id','category_name')->where('rootid', $category->rootid)->orderBy('category_name')->get();
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$subcategories = collect();
|
||||
}
|
||||
|
||||
if (! $subcategories || $subcategories->count() === 0) {
|
||||
$subcategories = $contentType->rootCategories()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name, 'slug' => $c->slug]);
|
||||
}
|
||||
|
||||
if ($artworks instanceof \Illuminate\Database\Eloquent\Collection || $artworks instanceof \Illuminate\Support\Collection) {
|
||||
$page = (int) ($request->query('page', 1));
|
||||
$artworks = new \Illuminate\Pagination\LengthAwarePaginator($artworks->values()->all(), $artworks->count(), $perPage, $page, [
|
||||
'path' => url()->current(),
|
||||
'query' => request()->query(),
|
||||
]);
|
||||
}
|
||||
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
|
||||
$page_meta_description = $tidy;
|
||||
|
||||
return view('legacy::content-type', compact('contentType','rootCategories','artworks','page_title','page_meta_description','subcategories','id'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
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' => DB::table('user_profiles')->where('user_id', $user->id)->value('avatar_hash'),
|
||||
'about_me' => $user->bio ?? null,
|
||||
];
|
||||
|
||||
return view('legacy::profile', [
|
||||
'user' => $legacyUser,
|
||||
'artworks' => $artworks,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ArtworkComment;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class ReceivedCommentsController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
if (! $user) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$hits = 33;
|
||||
$currentPage = max(1, (int) $request->query('page', 1));
|
||||
|
||||
$base = ArtworkComment::with(['user', 'artwork'])
|
||||
->whereHas('artwork', function ($q) use ($user) {
|
||||
$q->where('user_id', $user->id)->where('is_approved', true);
|
||||
})
|
||||
->orderByDesc('created_at');
|
||||
|
||||
$comments = $base->paginate($hits);
|
||||
|
||||
return view('legacy::received-comments', [
|
||||
'comments' => $comments,
|
||||
'currentPage' => $currentPage,
|
||||
'hits' => $hits,
|
||||
'total' => $comments->total(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ThumbnailPresenter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class StatisticsController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$userId = $request->user()->id;
|
||||
|
||||
$sort = (string) $request->query('sort', 'date');
|
||||
$allowed = ['date', 'name', 'dls', 'category', 'comments'];
|
||||
if (! in_array($sort, $allowed, true)) {
|
||||
$sort = 'date';
|
||||
}
|
||||
|
||||
$categorySub = DB::table('artwork_category as ac')
|
||||
->join('categories as c', 'ac.category_id', '=', 'c.id')
|
||||
->select('ac.artwork_id', DB::raw('MIN(c.name) as category_name'))
|
||||
->groupBy('ac.artwork_id');
|
||||
|
||||
$query = DB::table('artworks as a')
|
||||
->leftJoinSub($categorySub, 'cat', function ($join) {
|
||||
$join->on('a.id', '=', 'cat.artwork_id');
|
||||
})
|
||||
->where('a.user_id', $userId)
|
||||
->select([
|
||||
'a.*',
|
||||
DB::raw('cat.category_name as category_name'),
|
||||
])
|
||||
->selectRaw('(SELECT COUNT(*) FROM artwork_comments WHERE artwork_id = a.id) AS num_comments');
|
||||
|
||||
if ($sort === 'name') {
|
||||
$query->orderBy('a.name', 'asc');
|
||||
} elseif ($sort === 'dls') {
|
||||
$query->orderByDesc('a.dls');
|
||||
} elseif ($sort === 'category') {
|
||||
$query->orderBy('cat.category_name', 'asc');
|
||||
} elseif ($sort === 'comments') {
|
||||
$query->orderByDesc('num_comments');
|
||||
} else {
|
||||
$query->orderByDesc('a.published_at')->orderByDesc('a.id');
|
||||
}
|
||||
|
||||
$artworks = $query->paginate(20)->appends(['sort' => $sort]);
|
||||
|
||||
$artworks->getCollection()->transform(function ($row) {
|
||||
$thumb = ThumbnailPresenter::present($row, 'sm');
|
||||
$row->thumb_url = $thumb['url'] ?? '';
|
||||
$row->thumb_srcset = $thumb['srcset'] ?? null;
|
||||
return $row;
|
||||
});
|
||||
|
||||
return view('legacy::statistics', [
|
||||
'artworks' => $artworks,
|
||||
'sort' => $sort,
|
||||
'page_title' => 'Artwork Statistics',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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'] : 'https://files.skinbase.org/default/missing_md.webp';
|
||||
$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('web.downloads.today', ['page_title' => $page_title, 'artworks' => $paginator]);
|
||||
}
|
||||
}
|
||||
@@ -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::table('featured_works as t0')
|
||||
->leftJoin('artworks as t1', 't0.artwork_id', '=', 't1.id')
|
||||
->join('categories as t2', 't1.category', '=', 't2.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', DB::raw('t2.name as 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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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')
|
||||
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
||||
->select('u.id as user_id', 'u.name as uname', 'u.username', 'up.avatar_hash', '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,
|
||||
'avatar_hash' => $row->avatar_hash,
|
||||
'total' => (int) $row->total_metric,
|
||||
'metric' => $metric,
|
||||
];
|
||||
});
|
||||
|
||||
$page_title = 'Top Authors';
|
||||
|
||||
return view('legacy::top-authors', compact('page_title', 'authors', 'metric'));
|
||||
}
|
||||
}
|
||||
@@ -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::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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Services\AvatarService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
if (! $user) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
// Handle profile update
|
||||
if ($request->isMethod('post')) {
|
||||
$action = $request->input('confirm');
|
||||
|
||||
if ($action === 'true_password') {
|
||||
$old = $request->input('oldpass');
|
||||
$new = $request->input('newpass');
|
||||
$new2 = $request->input('newpass2');
|
||||
|
||||
if ($new && $new === $new2 && Hash::check($old, $user->password)) {
|
||||
$user->password = Hash::make($new);
|
||||
$user->save();
|
||||
$request->session()->flash('status', 'Password changed.');
|
||||
} else {
|
||||
$request->session()->flash('error', 'Password not changed.');
|
||||
}
|
||||
} else {
|
||||
// Map legacy form fields into the modern schema.
|
||||
$data = $request->only(['name','web','country_code','signature','description','about_me']);
|
||||
|
||||
// Core user column: `name`
|
||||
if (isset($data['name'])) {
|
||||
$user->name = $data['name'] ?? $user->name;
|
||||
}
|
||||
|
||||
// Collect other profile updates to persist into `user_profiles` when available
|
||||
$profileUpdates = [];
|
||||
if (!empty($data['web'])) $profileUpdates['website'] = $data['web'];
|
||||
if (!empty($data['signature'])) $profileUpdates['signature'] = $data['signature'];
|
||||
if (!empty($data['description'])) $profileUpdates['description'] = $data['description'];
|
||||
if (!empty($data['about_me'])) $profileUpdates['about'] = $data['about_me'];
|
||||
if (!empty($data['country_code'])) $profileUpdates['country_code'] = $data['country_code'];
|
||||
|
||||
$d1 = $request->input('date1');
|
||||
$d2 = $request->input('date2');
|
||||
$d3 = $request->input('date3');
|
||||
if ($d1 && $d2 && $d3) {
|
||||
$profileUpdates['birthdate'] = sprintf('%04d-%02d-%02d', (int)$d3, (int)$d2, (int)$d1);
|
||||
}
|
||||
|
||||
$userGender = $request->input('gender', $user->gender);
|
||||
if (!empty($userGender)) {
|
||||
$g = strtolower($userGender);
|
||||
$map = ['m' => 'M', 'f' => 'F', 'n' => 'X', 'x' => 'X'];
|
||||
$profileUpdates['gender'] = $map[$g] ?? strtoupper($userGender);
|
||||
}
|
||||
|
||||
$profileUpdates['mlist'] = $request->has('newsletter') ? 1 : 0;
|
||||
$profileUpdates['friend_upload_notice'] = $request->has('friend_upload_notice') ? 1 : 0;
|
||||
|
||||
// Files: avatar/photo/emoticon
|
||||
if ($request->hasFile('avatar')) {
|
||||
try {
|
||||
$hash = app(AvatarService::class)->storeFromUploadedFile((int) $user->id, $request->file('avatar'));
|
||||
$user->icon = $hash;
|
||||
} catch (\Throwable $e) {
|
||||
$request->session()->flash('error', 'Avatar upload failed.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->hasFile('personal_picture')) {
|
||||
$f = $request->file('personal_picture');
|
||||
$name = $user->id . '.' . $f->getClientOriginalExtension();
|
||||
$f->move(public_path('user-picture'), $name);
|
||||
$profileUpdates['cover_image'] = $name;
|
||||
$user->picture = $name;
|
||||
}
|
||||
|
||||
if ($request->hasFile('emotion_icon')) {
|
||||
$f = $request->file('emotion_icon');
|
||||
$name = $user->id . '.' . $f->getClientOriginalExtension();
|
||||
$f->move(public_path('emotion'), $name);
|
||||
$user->eicon = $name;
|
||||
}
|
||||
|
||||
// Save core user fields
|
||||
$user->save();
|
||||
|
||||
// Persist profile updates into `user_profiles` when available, otherwise fallback to `users` table
|
||||
try {
|
||||
if (!empty($profileUpdates) && Schema::hasTable('user_profiles')) {
|
||||
DB::table('user_profiles')->updateOrInsert(['user_id' => $user->id], $profileUpdates + ['updated_at' => now(), 'created_at' => now()]);
|
||||
} elseif (!empty($profileUpdates)) {
|
||||
DB::table('users')->where('id', $user->id)->update($profileUpdates);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore persistence errors for legacy path
|
||||
}
|
||||
|
||||
$request->session()->flash('status', 'Profile updated.');
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare birth date parts for the legacy form (initialized — parsed after merging profiles)
|
||||
$birthDay = null;
|
||||
$birthMonth = null;
|
||||
$birthYear = null;
|
||||
|
||||
// Load country list if available (legacy table names)
|
||||
$countries = collect();
|
||||
try {
|
||||
if (Schema::hasTable('country_list')) {
|
||||
$countries = DB::table('country_list')->orderBy('country_name')->get();
|
||||
} elseif (Schema::hasTable('countries')) {
|
||||
$countries = DB::table('countries')->orderBy('name')->get();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$countries = collect();
|
||||
}
|
||||
|
||||
// Merge modern `user_profiles` and `user_social_links` into the user object for the view
|
||||
try {
|
||||
if (Schema::hasTable('user_profiles')) {
|
||||
$profile = DB::table('user_profiles')->where('user_id', $user->id)->first();
|
||||
if ($profile) {
|
||||
// map modern profile fields onto the legacy user properties/helpers used by the view
|
||||
if (isset($profile->website)) $user->homepage = $profile->website;
|
||||
if (isset($profile->about)) $user->about_me = $profile->about;
|
||||
if (isset($profile->birthdate)) $user->birth = $profile->birthdate;
|
||||
if (isset($profile->gender)) $user->gender = $profile->gender;
|
||||
if (isset($profile->country_code)) $user->country_code = $profile->country_code;
|
||||
if (isset($profile->avatar_hash)) $user->icon = $profile->avatar_hash;
|
||||
if (isset($profile->cover_image)) $user->picture = $profile->cover_image;
|
||||
if (isset($profile->signature)) $user->signature = $profile->signature;
|
||||
if (isset($profile->description)) $user->description = $profile->description;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore profile merge errors
|
||||
}
|
||||
|
||||
try {
|
||||
if (Schema::hasTable('user_social_links')) {
|
||||
$social = DB::table('user_social_links')->where('user_id', $user->id)->first();
|
||||
if ($social) {
|
||||
$user->social = $social;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore social links errors
|
||||
}
|
||||
|
||||
// Parse birth date parts after merging `user_profiles` so profile birthdate is used
|
||||
if (! empty($user->birth)) {
|
||||
try {
|
||||
$dt = Carbon::parse($user->birth);
|
||||
$birthDay = $dt->format('d');
|
||||
$birthMonth = $dt->format('m');
|
||||
$birthYear = $dt->format('Y');
|
||||
} catch (\Throwable $e) {
|
||||
// ignore parse errors
|
||||
}
|
||||
}
|
||||
|
||||
return view('legacy::user', [
|
||||
'user' => $user,
|
||||
'birthDay' => $birthDay,
|
||||
'birthMonth' => $birthMonth,
|
||||
'birthYear' => $birthYear,
|
||||
'countries' => $countries,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user