current state

This commit is contained in:
2026-02-08 10:42:01 +01:00
parent 0a4372c40d
commit e055af9248
70 changed files with 4882 additions and 330 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ArtworkController extends Controller
{
public function index(Request $request)
{
abort(404);
}
public function create(Request $request)
{
abort(404);
}
public function store(Request $request)
{
abort(404);
}
public function edit(Request $request, int $id)
{
abort(404);
}
public function update(Request $request, int $id)
{
abort(404);
}
public function destroy(Request $request, int $id)
{
abort(404);
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\ContentType;
use App\Models\Artwork;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -16,6 +17,7 @@ class CategoryPageController extends Controller
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();
@@ -41,6 +43,7 @@ class CategoryPageController extends Controller
->where('slug', strtolower(array_shift($segments)))
->first();
if (! $current) {
abort(404);
}
@@ -56,12 +59,28 @@ class CategoryPageController extends Controller
$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(),
]);
// Collect category ids for the category + all descendants recursively
$collected = [];
$gather = function (Category $cat) use (&$gather, &$collected) {
$collected[] = $cat->id;
foreach ($cat->children as $child) {
$gather($child);
}
};
// Ensure children relation is loaded to avoid N+1 recursion
$category->load('children');
$gather($category);
// Load artworks that are attached to any of these categories
$query = Artwork::whereHas('categories', function ($q) use ($collected) {
$q->whereIn('categories.id', $collected);
})->published()->public();
// Paginate results
$perPage = 40;
$artworks = $query->orderBy('published_at', 'desc')
->paginate($perPage)
->withQueryString();
$page_title = $category->name;
$page_meta_description = $category->description ?? ($contentType->name . ' artworks on Skinbase');

View File

@@ -2,7 +2,12 @@
namespace App\Http\Controllers;
abstract class Controller
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
abstract class Controller extends BaseController
{
//
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@@ -0,0 +1,102 @@
<?php
namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use App\Http\Requests\Dashboard\UpdateArtworkRequest;
use App\Models\Artwork;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
class ArtworkController extends Controller
{
public function index(Request $request): View
{
$artworks = $request->user()
->artworks()
->latest()
->paginate(20);
return view('artworks.index', [
'artworks' => $artworks,
'page_title' => 'My Artworks',
]);
}
public function edit(Request $request, int $id): View
{
$artwork = $request->user()->artworks()->whereKey($id)->firstOrFail();
$this->authorize('update', $artwork);
return view('artworks.edit', [
'artwork' => $artwork,
'page_title' => 'Edit Artwork',
]);
}
public function update(UpdateArtworkRequest $request, int $id): RedirectResponse
{
$artwork = $request->user()->artworks()->whereKey($id)->firstOrFail();
$this->authorize('update', $artwork);
$data = $request->validated();
$artwork->title = $data['title'];
$artwork->description = $data['description'] ?? null;
if ($request->hasFile('file')) {
$file = $request->file('file');
// Remove prior stored file if it's on the public disk.
if (! empty($artwork->file_path) && Storage::disk('public')->exists($artwork->file_path)) {
Storage::disk('public')->delete($artwork->file_path);
}
$size = $file->getSize() ?? 0;
$mime = $file->getMimeType() ?? 'application/octet-stream';
$dimensions = @getimagesize($file->getRealPath());
$width = is_array($dimensions) ? (int) ($dimensions[0] ?? 0) : 0;
$height = is_array($dimensions) ? (int) ($dimensions[1] ?? 0) : 0;
$path = $file->storePublicly('artworks', 'public');
$artwork->file_name = $file->getClientOriginalName();
$artwork->file_path = $path;
$artwork->file_size = (int) $size;
$artwork->mime_type = (string) $mime;
$artwork->width = max(1, $width);
$artwork->height = max(1, $height);
// If a file is replaced, clear CDN-derived fields unless a separate pipeline repopulates them.
$artwork->hash = null;
$artwork->thumb_ext = null;
$artwork->file_ext = $file->guessExtension() ?: $file->getClientOriginalExtension() ?: null;
}
$artwork->save();
return redirect()
->route('dashboard.artworks.edit', $artwork->id)
->with('status', 'Artwork updated.');
}
public function destroy(Request $request, int $id): RedirectResponse
{
$artwork = $request->user()->artworks()->whereKey($id)->firstOrFail();
$this->authorize('delete', $artwork);
// Best-effort remove stored file.
if (! empty($artwork->file_path) && Storage::disk('public')->exists($artwork->file_path)) {
Storage::disk('public')->delete($artwork->file_path);
}
$artwork->delete();
return redirect()
->route('dashboard.artworks.index')
->with('status', 'Artwork deleted.');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Artwork;
use App\Models\User;
use Illuminate\Support\Facades\Schema;
class GalleryController extends Controller
{
public function show(Request $request, $userId, $username = null)
{
$user = User::find((int)$userId);
if (! $user) {
abort(404);
}
$page = max(1, (int) $request->query('page', 1));
$hits = 20;
$query = Artwork::where('user_id', $user->id)
->approved()
->published()
->public()
->orderByDesc('published_at');
$total = (int) $query->count();
$artworks = $query->skip(($page - 1) * $hits)->take($hits)->get();
return view('legacy.gallery', [
'user' => $user,
'artworks' => $artworks,
'page' => $page,
'hits' => $hits,
'total' => $total,
]);
}
}

View File

@@ -21,7 +21,7 @@ class ArtController extends Controller
if ($request->isMethod('post') && $request->input('action') === 'store_comment') {
if (auth()->check()) {
try {
\Illuminate\Support\Facades\DB::connection('legacy')->table('artworks_comments')->insert([
DB::table('artwork_comments')->insert([
'artwork_id' => (int)$id,
'owner_user_id' => (int)($request->user()->id ?? 0),
'user_id' => (int)$request->user()->id,
@@ -44,7 +44,7 @@ class ArtController extends Controller
// load comments for artwork (legacy schema)
try {
$comments = \Illuminate\Support\Facades\DB::connection('legacy')->table('artworks_comments as t1')
$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)

View File

@@ -17,7 +17,7 @@ class AvatarController extends Controller
$defaultAvatar = public_path('gfx/avatar.jpg');
try {
$icon = DB::connection('legacy')->table('users')->where('user_id', $user_id)->value('icon');
$icon = DB::table('users')->where('user_id', $user_id)->value('icon');
} catch (\Throwable $e) {
$icon = null;
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\Legacy;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BuddiesController extends Controller
{
public function index(Request $request)
{
$user = $request->user();
if (! $user) {
return redirect()->route('login');
}
$perPage = 50;
try {
$query = DB::table('friends_list as t1')
->leftJoin('users as t2', 't1.user_id', '=', 't2.id')
->leftJoin('user_profiles as p', 'p.user_id', '=', 't2.id')
->where('t1.friend_id', $user->id)
->select('t1.id', 't1.user_id', 't1.friend_id', 't2.name as uname', 'p.avatar as icon', 't1.date_added')
->orderByDesc('t1.date_added');
$followers = $query->paginate($perPage)->withQueryString();
} catch (\Throwable $e) {
$followers = collect();
}
$page_title = ($user->name ?? $user->username ?? 'User') . ': Followers';
return view('legacy.buddies', compact('followers', 'page_title'));
}
}

View File

@@ -38,7 +38,7 @@ class ChatController extends Controller
// Load smileys from legacy DB
try {
$smileys = DB::connection('legacy')->table('smileys')->select('code', 'picture', 'emotion')->get();
$smileys = DB::table('smileys')->select('code', 'picture', 'emotion')->get();
} catch (\Throwable $e) {
$smileys = collect();
}

View File

@@ -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');
}
}

View File

@@ -21,19 +21,19 @@ class InterviewController extends Controller
$interviewId = (int) $request->input('interview_id');
try {
DB::connection('legacy')->table('interviews_comment')->insert([
DB::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')
$ar2 = DB::table('users')
->where('uname', $_SESSION['web_login']['username'])
->first();
if (!empty($ar2->user_id)) {
DB::connection('legacy')->table('users_statistics')
DB::table('users_statistics')
->where('user_id', $ar2->user_id)
->increment('newscomment');
}
@@ -44,7 +44,7 @@ class InterviewController extends Controller
}
try {
$ar = DB::connection('legacy')->table('interviews')->where('id', $id)->first();
$ar = DB::table('interviews')->where('id', $id)->first();
} catch (\Throwable $e) {
$ar = null;
}
@@ -54,7 +54,7 @@ class InterviewController extends Controller
}
try {
$artworks = DB::connection('legacy')->table('wallz')
$artworks = DB::table('wallz')
->where('uname', $ar->username)
->inRandomOrder()
->limit(2)
@@ -64,7 +64,7 @@ class InterviewController extends Controller
}
try {
$comments = DB::connection('legacy')->table('interviews_comment as c')
$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')
@@ -79,7 +79,7 @@ class InterviewController extends Controller
$postCounts = [];
if (!empty($authors)) {
try {
$counts = DB::connection('legacy')->table('interviews_comment')
$counts = DB::table('interviews_comment')
->select('author', DB::raw('COUNT(*) as cnt'))
->whereIn('author', $authors)
->groupBy('author')

View File

@@ -11,7 +11,7 @@ class InterviewsController extends Controller
public function index(Request $request)
{
try {
$interviews = DB::connection('legacy')->table('interviews AS t1')
$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')

View File

@@ -13,7 +13,7 @@ class MonthlyCommentatorsController extends Controller
$hits = 30;
$page = max(1, (int) $request->query('page', 1));
$query = DB::connection('legacy')->table('artworks_comments as t1')
$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)

View 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\Facades\Auth;
class MyBuddiesController extends Controller
{
public function index(Request $request)
{
$user = $request->user();
if (! $user) {
return redirect()->route('login');
}
$perPage = 50;
try {
$query = DB::table('friends_list as t1')
->leftJoin('users as t2', 't1.friend_id', '=', 't2.id')
->leftJoin('user_profiles as p', 'p.user_id', '=', 't2.id')
->where('t1.user_id', $user->id)
->select('t1.id', 't1.friend_id', 't1.user_id', 't2.name as uname', 'p.avatar as icon', 't1.date_added')
->orderByDesc('t1.date_added');
$buddies = $query->paginate($perPage)->withQueryString();
} catch (\Throwable $e) {
$buddies = collect();
}
$page_title = ($user->name ?? $user->username ?? 'User') . ': Following List';
return view('legacy.mybuddies', compact('buddies', 'page_title'));
}
public function destroy(Request $request, $id)
{
$user = $request->user();
if (! $user) {
abort(403);
}
try {
$deleted = DB::table('friends_list')->where('id', $id)->where('user_id', $user->id)->delete();
if ($deleted) {
$request->session()->flash('status', 'Removed from following list.');
}
} catch (\Throwable $e) {
$request->session()->flash('error', 'Could not remove buddy.');
}
return redirect()->route('legacy.mybuddies');
}
}

View File

@@ -13,7 +13,7 @@ class NewsController extends Controller
$id = (int) $id;
try {
$news = DB::connection('legacy')->table('news as t1')
$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')
@@ -27,7 +27,7 @@ class NewsController extends Controller
}
try {
$comments = DB::connection('legacy')->table('news_comment as c')
$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')

View File

@@ -0,0 +1,81 @@
<?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\Models\ContentType;
class PhotographyController extends Controller
{
protected ArtworkService $artworks;
public function __construct(ArtworkService $artworks)
{
$this->artworks = $artworks;
}
public function index(Request $request)
{
// Legacy group mapping: Photography => id 3
$group = 'Photography';
$id = 3;
// Fetch legacy category info if available
$category = null;
try {
if (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 ?? 'Photography';
$tidy = $category->description ?? null;
$perPage = 40;
// Use ArtworkService to get artworks for the content type 'photography'
try {
$artworks = $this->artworks->getArtworksByContentType('photography', $perPage);
} catch (\Throwable $e) {
$artworks = collect();
}
// Load subcategories (legacy) if available
$subcategories = collect();
try {
if (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();
}
// Fallback to authoritative categories table when legacy table is missing/empty
if (! $subcategories || $subcategories->count() === 0) {
$ct = ContentType::where('slug', 'photography')->first();
if ($ct) {
$subcategories = $ct->rootCategories()
->orderBy('sort_order')
->orderBy('name')
->get()
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name]);
} else {
$subcategories = collect();
}
}
return view('legacy.photography', compact('page_title','tidy','group','artworks','subcategories','id'));
}
}

View File

@@ -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;
$page = 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,
'page' => $page,
'hits' => $hits,
'total' => $comments->total(),
]);
}
}

View File

@@ -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',
]);
}
}

View File

@@ -13,13 +13,13 @@ class TodayInHistoryController extends Controller
$hits = 39;
try {
$base = DB::connection('legacy')->table('featured_works as t0')
$base = DB::table('featured_works as t0')
->leftJoin('artworks as t1', 't0.artwork_id', '=', 't1.id')
->join('artworks_categories as t2', 't1.category', '=', 't2.category_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', 't2.category_name');
->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) {

View File

@@ -58,72 +58,3 @@ class TopAuthorsController extends Controller
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'));
}
}

View File

@@ -15,7 +15,7 @@ class TopFavouritesController extends Controller
$hits = 21;
$page = max(1, (int) $request->query('page', 1));
$base = DB::connection('legacy')->table('artworks_favourites as t1')
$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'))

View File

@@ -0,0 +1,120 @@
<?php
namespace App\Http\Controllers\Legacy;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\Models\User;
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 {
$data = $request->only(['real_name','web','country_code','signature','description','about_me']);
$user->real_name = $data['real_name'] ?? $user->real_name;
$user->web = $data['web'] ?? $user->web;
$user->country_code = $data['country_code'] ?? $user->country_code;
$user->signature = $data['signature'] ?? $user->signature;
$user->description = $data['description'] ?? $user->description;
$user->about_me = $data['about_me'] ?? $user->about_me;
$d1 = $request->input('date1');
$d2 = $request->input('date2');
$d3 = $request->input('date3');
if ($d1 && $d2 && $d3) {
$user->birth = sprintf('%04d-%02d-%02d', (int)$d3, (int)$d2, (int)$d1);
}
$user->gender = $request->input('gender', $user->gender);
$user->mlist = $request->has('newsletter') ? 1 : 0;
$user->friend_upload_notice = $request->has('friend_upload_notice') ? 1 : 0;
if ($request->hasFile('avatar')) {
$f = $request->file('avatar');
$name = $user->id . '.' . $f->getClientOriginalExtension();
$f->move(public_path('avatar'), $name);
$user->icon = $name;
}
if ($request->hasFile('personal_picture')) {
$f = $request->file('personal_picture');
$name = $user->id . '.' . $f->getClientOriginalExtension();
$f->move(public_path('user-picture'), $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;
}
$user->save();
$request->session()->flash('status', 'Profile updated.');
}
}
// Prepare birth date parts for the legacy form
$birthDay = null;
$birthMonth = null;
$birthYear = null;
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
}
}
// 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();
}
return view('legacy.user', [
'user' => $user,
'birthDay' => $birthDay,
'birthMonth' => $birthMonth,
'birthYear' => $birthYear,
'countries' => $countries,
]);
}
}

View File

@@ -44,10 +44,10 @@ class LegacyController extends Controller
$perPage = 50;
try {
$artworks = DB::connection('legacy')->table('wallz as w')
->leftJoin('artworks_categories as c', 'w.category', '=', 'c.category_id')
$artworks = DB::table('wallz as w')
->leftJoin('categories as c', 'w.category', '=', 'c.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')
->select('w.id', 'w.name', 'w.picture', 'w.category', 'w.datum', DB::raw('c.name as category_name'), 'u.uname')
->where('w.approved', 1)
->where('w.public', 'Y')
->orderByDesc('w.datum')
@@ -101,10 +101,10 @@ class LegacyController extends Controller
$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)
try {
$category = DB::table('categories')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'), 'description', DB::raw('parent_id as rootid'), DB::raw('content_type_id as section_id'))
->where('id', $id)
->first();
} catch (\Throwable $e) {
$category = null;
@@ -117,9 +117,9 @@ class LegacyController extends Controller
$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')
$base = DB::table('wallz as t1')
->select('t1.id', 't1.name', 't1.picture', 't3.uname', 't1.category', DB::raw('t2.name as category_name'))
->join('categories as t2', 't1.category', '=', 't2.id')
->leftJoin('users as t3', 't1.user_id', '=', 't3.user_id')
->where('t1.approved', 1)
->where(function ($q) use ($id, $category) {
@@ -139,22 +139,22 @@ class LegacyController extends Controller
}
try {
$subcategories = DB::connection('legacy')->table('artworks_categories')
->select('category_id', 'category_name')
->where('rootid', $id)
$subcategories = DB::table('categories')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'))
->where('parent_id', $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)
$subcategories = DB::table('categories')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'))
->where('parent_id', $category->rootid)
->orderBy('category_name')
->get();
}
if ($subcategories->isEmpty()) {
$subcategories = DB::connection('legacy')->table('skupine')
$subcategories = DB::table('skupine')
->select('category_id', 'category_name')
->where('rootid', $id)
->orderBy('category_name')
@@ -162,7 +162,7 @@ class LegacyController extends Controller
}
} catch (\Throwable $e) {
try {
$subcategories = DB::connection('legacy')->table('skupine')
$subcategories = DB::table('skupine')
->select('category_id', 'category_name')
->where('rootid', $id)
->orderBy('category_name')
@@ -191,16 +191,16 @@ class LegacyController extends Controller
// 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')
$categories = DB::table('categories')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'), 'description')
->where('content_type_id', 0)
->where(DB::raw('parent_id'), 0)
->orderBy('id')
->get();
// Fallback to legacy table name if empty
if ($categories->isEmpty()) {
$categories = DB::connection('legacy')->table('skupine')
$categories = DB::table('skupine')
->select('category_id', 'category_name', 'description')
->where('section_id', 0)
->where('rootid', 0)
@@ -209,7 +209,7 @@ class LegacyController extends Controller
}
} catch (\Throwable $e) {
try {
$categories = DB::connection('legacy')->table('skupine')
$categories = DB::table('skupine')
->select('category_id', 'category_name', 'description')
->where('section_id', 0)
->where('rootid', 0)
@@ -225,15 +225,15 @@ class LegacyController extends Controller
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)
$subs = DB::table('categories')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'), 'image as picture', DB::raw('content_type_id as section_id'))
->whereIn('content_type_id', $ids)
->orderBy('category_name')
->get();
if ($subs->isEmpty()) {
// fallback to skupine table naming
$subs = DB::connection('legacy')->table('skupine')
$subs = DB::table('skupine')
->select('category_id', 'category_name', 'picture', 'section_id')
->whereIn('section_id', $ids)
->orderBy('category_name')
@@ -262,7 +262,7 @@ class LegacyController extends Controller
$page_meta_keywords = 'forum, discussions, topics, skinbase';
try {
$topics = DB::connection('legacy')->table('forum_topics as t')
$topics = DB::table('forum_topics as t')
->select(
't.topic_id',
't.topic',
@@ -292,7 +292,7 @@ class LegacyController extends Controller
public function forumTopic(Request $request, int $topic_id)
{
try {
$topic = DB::connection('legacy')->table('forum_topics')->where('topic_id', $topic_id)->first();
$topic = DB::table('forum_topics')->where('topic_id', $topic_id)->first();
} catch (\Throwable $e) {
$topic = null;
}
@@ -307,7 +307,7 @@ class LegacyController extends Controller
// 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')
$subtopics = DB::table('forum_topics as t')
->leftJoin('users as u', 't.user_id', '=', 'u.user_id')
->select(
't.topic_id',
@@ -348,7 +348,7 @@ class LegacyController extends Controller
]);
try {
$posts = DB::connection('legacy')->table('forum_posts as p')
$posts = DB::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)
@@ -361,7 +361,7 @@ class LegacyController extends Controller
if ($posts->total() === 0) {
try {
$posts = DB::connection('legacy')->table('forum_posts as p')
$posts = DB::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)
@@ -391,14 +391,14 @@ class LegacyController extends Controller
$memberFeatured = null;
try {
$featured = DB::connection('legacy')->table('featured_works as fw')
$featured = DB::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')
$memberFeatured = DB::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')
@@ -437,7 +437,7 @@ class LegacyController extends Controller
private function forumNews(): array
{
try {
return DB::connection('legacy')->table('forum_topics as t1')
return DB::table('forum_topics as t1')
->leftJoin('users as t2', 't1.user_id', '=', 't2.user_id')
->select(
't1.topic_id',
@@ -461,7 +461,7 @@ class LegacyController extends Controller
private function ourNews(): array
{
try {
return DB::connection('legacy')->table('news as t1')
return DB::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(
@@ -487,7 +487,7 @@ class LegacyController extends Controller
private function latestForumActivity(): array
{
try {
return DB::connection('legacy')->table('forum_topics as t1')
return DB::table('forum_topics as t1')
->select(
't1.topic_id',
't1.topic',
@@ -523,9 +523,9 @@ class LegacyController extends Controller
// Fallback to DB if cache missing
if (empty($uploads)) {
try {
$uploads = DB::connection('legacy')->table('wallz as w')
$uploads = DB::table('wallz as w')
->leftJoin('users as u', 'w.user_id', '=', 'u.user_id')
->leftJoin('artworks_categories as c', 'w.category', '=', 'c.category_id')
->leftJoin('categories as c', 'w.category', '=', 'c.id')
->where('w.approved', 1)
->orderByDesc('w.datum')
->limit(20)
@@ -536,7 +536,7 @@ class LegacyController extends Controller
'name' => $row->name,
'picture' => $row->picture,
'uname' => $row->uname,
'category_name' => $row->category_name ?? '',
'category_name' => $row->category_name ?? $row->name ?? '',
];
})
->toArray();

View File

@@ -15,12 +15,19 @@ class ManageController extends Controller
$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')
// Use default connection query builder and join category name to avoid Eloquent model issues
$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.*', 'c.category_name')
->orderByDesc('a.datum')
->select('a.*', DB::raw('cat.category_name as category_name'))
->orderByDesc('a.published_at')
->orderByDesc('a.id');
$artworks = $query->paginate($perPage);
@@ -34,12 +41,20 @@ class ManageController extends Controller
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();
$artwork = DB::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();
// If artworks no longer have a single `category` column, fetch pivot selection
$selectedCategory = DB::table('artwork_category')->where('artwork_id', (int)$id)->value('category_id');
$artwork->category = $selectedCategory;
$categories = DB::table('categories')
->where('content_type_id', 0)
->orderBy('id')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'))
->get();
return view('manage.edit', [
'artwork' => $artwork,
@@ -51,7 +66,7 @@ class ManageController extends Controller
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();
$existing = DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
if (! $existing) {
abort(404);
@@ -66,7 +81,6 @@ class ManageController extends Controller
]);
$update = [
'name' => $data['name'],
'category' => $data['section'] ?? $existing->category,
'description' => $data['description'] ?? $existing->description,
'updated' => now(),
];
@@ -86,7 +100,16 @@ class ManageController extends Controller
$update['fname'] = basename($attPath);
}
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->update($update);
DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->update($update);
// Update pivot: set single category selection for this artwork
if (isset($data['section'])) {
DB::table('artwork_category')->where('artwork_id', (int)$id)->delete();
DB::table('artwork_category')->insert([
'artwork_id' => (int)$id,
'category_id' => (int)$data['section'],
]);
}
return redirect()->route('manage')->with('status', 'Artwork was successfully updated.');
}
@@ -94,7 +117,7 @@ class ManageController extends Controller
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();
$artwork = DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
if (! $artwork) {
abort(404);
}
@@ -107,7 +130,7 @@ class ManageController extends Controller
Storage::delete('public/uploads/artworks/' . $artwork->picture);
}
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->delete();
DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->delete();
return redirect()->route('manage')->with('status', 'Artwork deleted.');
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\Dashboard;
use Illuminate\Foundation\Http\FormRequest;
class UpdateArtworkRequest extends FormRequest
{
public function authorize(): bool
{
// Authorization is enforced in the controller via ArtworkPolicy.
return true;
}
public function rules(): array
{
return [
'title' => 'required|string|max:150',
'description' => 'nullable|string',
// 100MB max (Laravel uses kilobytes)
'file' => 'nullable|image|max:102400',
];
}
}