Upload beautify

This commit is contained in:
2026-02-14 15:14:12 +01:00
parent e129618910
commit 79192345e3
249 changed files with 24436 additions and 1021 deletions

View File

@@ -21,61 +21,105 @@ class PhotographyController extends Controller
public function index(Request $request)
{
// Legacy group mapping: Photography => id 3
$group = 'Photography';
$id = 3;
// Determine the requested content type from the first URL segment (photography|wallpapers|skins)
$segment = strtolower($request->segment(1) ?? 'photography');
$contentSlug = in_array($segment, ['photography','wallpapers','skins','other']) ? $segment : 'photography';
// 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();
// Human-friendly group name (used by legacy templates)
$group = ucfirst($contentSlug);
// Try to load legacy category id only for photography (legacy mapping); otherwise prefer authoritative ContentType
$id = null;
if ($contentSlug === 'photography') {
$id = 3; // legacy root id for photography in oldSite (kept for backward compatibility)
}
} catch (\Throwable $e) {
// Fetch legacy category info if available (only when we have an id)
$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();
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;
}
} 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 {
// Page title and description: prefer legacy category when present, otherwise use ContentType data
$ct = ContentType::where('slug', $contentSlug)->first();
$page_title = $category->category_name ?? ($ct->name ?? ucfirst($contentSlug));
$tidy = $category->description ?? ($ct->description ?? null);
$perPage = 40;
// Load artworks for the requested content type using standard pagination
try {
$artQuery = \App\Models\Artwork::public()
->published()
->whereHas('categories', function ($q) use ($ct) {
$q->where('categories.content_type_id', $ct->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
$artworks = $artQuery->paginate($perPage)->withQueryString();
} catch (\Throwable $e) {
// Return an empty paginator so views using ->links() / ->firstItem() work
$artworks = new \Illuminate\Pagination\LengthAwarePaginator([], 0, $perPage, 1, [
'path' => url()->current(),
]);
}
// Load subcategories: prefer legacy table when id present and data exists, otherwise use ContentType root categories
$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();
}
}
return view('legacy.photography', compact('page_title','tidy','group','artworks','subcategories','id'));
if (! $subcategories || $subcategories->count() === 0) {
if ($ct) {
$subcategories = $ct->rootCategories()
->orderBy('sort_order')
->orderBy('name')
->get()
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name, 'slug' => $c->slug]);
} else {
$subcategories = collect();
}
}
// Coerce collections to a paginator so the view's pagination helpers work
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(),
]);
}
// Prepare variables for the modern content-type view
$contentType = ContentType::where('slug', $contentSlug)->first();
$rootCategories = $contentType
? $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get()
: collect();
$page_meta_description = $tidy;
return view('legacy.content-type', compact('contentType','rootCategories','artworks','page_title','page_meta_description','subcategories','id'));
}
}

View File

@@ -37,29 +37,46 @@ class UserController extends Controller
$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;
// 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) {
$user->birth = sprintf('%04d-%02d-%02d', (int)$d3, (int)$d2, (int)$d1);
$profileUpdates['birthdate'] = 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;
$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')) {
$f = $request->file('avatar');
$name = $user->id . '.' . $f->getClientOriginalExtension();
$f->move(public_path('avatar'), $name);
// store filename in profile avatar (legacy field) — modern avatar pipeline will later migrate
$profileUpdates['avatar'] = $name;
$user->icon = $name;
}
@@ -67,6 +84,7 @@ class UserController extends Controller
$f = $request->file('personal_picture');
$name = $user->id . '.' . $f->getClientOriginalExtension();
$f->move(public_path('user-picture'), $name);
$profileUpdates['cover_image'] = $name;
$user->picture = $name;
}
@@ -77,25 +95,28 @@ class UserController extends Controller
$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
// Prepare birth date parts for the legacy form (initialized — parsed after merging profiles)
$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();
@@ -109,6 +130,50 @@ class UserController extends Controller
$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)) $user->icon = $profile->avatar;
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,