prepared and gallery fixes
This commit is contained in:
@@ -18,6 +18,30 @@ class ArtController extends Controller
|
||||
|
||||
public function show(Request $request, $id, $slug = null)
|
||||
{
|
||||
// canonicalize to new artwork route when possible
|
||||
try {
|
||||
$art = \App\Models\Artwork::find((int)$id);
|
||||
if ($art && !empty($art->slug)) {
|
||||
if ($slug !== $art->slug) {
|
||||
// attempt to derive contentType and category for route
|
||||
$category = $art->categories()->with('contentType')->first();
|
||||
if ($category && $category->contentType) {
|
||||
$contentTypeSlug = $category->contentType->slug ?? 'other';
|
||||
$categoryPath = $category->slug ?? $category->category_name ?? 'other';
|
||||
return redirect(route('artworks.show', [
|
||||
'contentTypeSlug' => $contentTypeSlug,
|
||||
'categoryPath' => $categoryPath,
|
||||
'artwork' => $art->slug,
|
||||
]), 301);
|
||||
} elseif (!empty($art->slug)) {
|
||||
// fallback: redirect to artwork slug only (may be handled by router)
|
||||
return redirect('/' . $art->slug, 301);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore and continue rendering legacy view
|
||||
}
|
||||
if ($request->isMethod('post') && $request->input('action') === 'store_comment') {
|
||||
if (auth()->check()) {
|
||||
try {
|
||||
|
||||
@@ -4,10 +4,10 @@ namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\ContentType;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Http\Controllers\ArtworkController as ArtworkControllerAlias;
|
||||
|
||||
class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
@@ -120,13 +120,32 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function showArtwork(Request $request, string $contentTypeSlug, string $categoryPath, string $artwork)
|
||||
public function showArtwork(...$params)
|
||||
{
|
||||
return app(\App\Http\Controllers\ArtController::class)->show(
|
||||
$request,
|
||||
strtolower($contentTypeSlug),
|
||||
trim($categoryPath, '/'),
|
||||
$artwork
|
||||
$req = request();
|
||||
$pathSegments = array_values(array_filter(explode('/', trim($req->path(), '/'))));
|
||||
|
||||
$contentTypeSlug = $params[0] ?? ($pathSegments[0] ?? null);
|
||||
$categoryPath = $params[1] ?? null;
|
||||
$artwork = $params[2] ?? null;
|
||||
|
||||
// If artwork wasn't provided (some route invocations supply fewer args),
|
||||
// derive it from the request path's last segment.
|
||||
if ($artwork === null) {
|
||||
$artwork = end($pathSegments) ?: null;
|
||||
}
|
||||
|
||||
$contentTypeSlug = strtolower((string) $contentTypeSlug);
|
||||
$categoryPath = $categoryPath !== null ? trim((string) $categoryPath, '/') : (isset($pathSegments[1]) ? implode('/', array_slice($pathSegments, 1, max(0, count($pathSegments) - 2))) : '');
|
||||
|
||||
// Normalize artwork param if route-model binding returned an Artwork model
|
||||
$artworkSlug = $artwork instanceof Artwork ? (string) $artwork->slug : (string) $artwork;
|
||||
|
||||
return app(\App\Http\Controllers\ArtworkController::class)->show(
|
||||
$req,
|
||||
$contentTypeSlug,
|
||||
$categoryPath,
|
||||
$artworkSlug
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,19 @@ class GalleryController extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// canonicalize username in URL when possible
|
||||
try {
|
||||
$correctName = $user->name ?? $user->uname ?? null;
|
||||
if ($username && $correctName && $username !== $correctName) {
|
||||
$qs = $request->getQueryString();
|
||||
$url = route('legacy.gallery', ['id' => $user->id, 'username' => $correctName]);
|
||||
if ($qs) $url .= '?' . $qs;
|
||||
return redirect($url, 301);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
$hits = 20;
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
@@ -36,34 +38,49 @@ class HomeController extends Controller
|
||||
$latestUploads = $this->artworks->getLatestArtworks(20);
|
||||
|
||||
// Forum news (root forum section id 2876)
|
||||
$forumNews = DB::table('forum_topics as t1')
|
||||
->leftJoin('users as u', 't1.user_id', '=', 'u.user_id')
|
||||
->select('t1.topic_id', 't1.topic', 'u.uname', 't1.post_date', 't1.preview')
|
||||
->where('t1.root_id', 2876)
|
||||
->where('t1.privilege', '<', 4)
|
||||
->orderBy('t1.post_date', 'desc')
|
||||
->limit(8)
|
||||
->get();
|
||||
try {
|
||||
$forumNews = DB::table('forum_topics as t1')
|
||||
->leftJoin('users as u', 't1.user_id', '=', 'u.user_id')
|
||||
->select('t1.topic_id', 't1.topic', 'u.uname', 't1.post_date', 't1.preview')
|
||||
->where('t1.root_id', 2876)
|
||||
->where('t1.privilege', '<', 4)
|
||||
->orderBy('t1.post_date', 'desc')
|
||||
->limit(8)
|
||||
->get();
|
||||
} catch (QueryException $e) {
|
||||
Log::warning('Forum topics table missing or DB error when loading forum news', ['exception' => $e->getMessage()]);
|
||||
$forumNews = collect();
|
||||
}
|
||||
|
||||
// Our news (latest site news)
|
||||
$ourNews = DB::table('news as t1')
|
||||
->join('news_categories as c', 't1.category_id', '=', 'c.category_id')
|
||||
->join('users as u', 't1.user_id', '=', 'u.user_id')
|
||||
->selectRaw('t1.news_id, t1.headline, t1.user_id, t1.picture, t1.preview, u.uname, t1.create_date, t1.views, c.category_name, (SELECT COUNT(*) FROM news_comments WHERE news_id = t1.news_id) AS num_comments')
|
||||
->orderBy('t1.create_date', 'desc')
|
||||
->limit(5)
|
||||
->get();
|
||||
try {
|
||||
$ourNews = DB::table('news as t1')
|
||||
->join('news_categories as c', 't1.category_id', '=', 'c.category_id')
|
||||
->join('users as u', 't1.user_id', '=', 'u.user_id')
|
||||
->selectRaw('t1.news_id, t1.headline, t1.user_id, t1.picture, t1.preview, u.uname, t1.create_date, t1.views, c.category_name, (SELECT COUNT(*) FROM news_comments WHERE news_id = t1.news_id) AS num_comments')
|
||||
->orderBy('t1.create_date', 'desc')
|
||||
->limit(5)
|
||||
->get();
|
||||
} catch (QueryException $e) {
|
||||
Log::warning('News table missing or DB error when loading our news', ['exception' => $e->getMessage()]);
|
||||
$ourNews = collect();
|
||||
}
|
||||
|
||||
// Latest forum activity (exclude rootless and news root)
|
||||
$latestForumActivity = DB::table('forum_topics as t1')
|
||||
->selectRaw('t1.topic_id, t1.topic, (SELECT COUNT(*) FROM forum_posts WHERE topic_id = t1.topic_id) AS numPosts')
|
||||
->where('t1.root_id', '<>', 0)
|
||||
->where('t1.root_id', '<>', 2876)
|
||||
->where('t1.privilege', '<', 4)
|
||||
->orderBy('t1.last_update', 'desc')
|
||||
->orderBy('t1.post_date', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
try {
|
||||
$latestForumActivity = DB::table('forum_topics as t1')
|
||||
->selectRaw('t1.topic_id, t1.topic, (SELECT COUNT(*) FROM forum_posts WHERE topic_id = t1.topic_id) AS numPosts')
|
||||
->where('t1.root_id', '<>', 0)
|
||||
->where('t1.root_id', '<>', 2876)
|
||||
->where('t1.privilege', '<', 4)
|
||||
->orderBy('t1.last_update', 'desc')
|
||||
->orderBy('t1.post_date', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
} catch (QueryException $e) {
|
||||
Log::warning('Forum topics table missing or DB error when loading latest forum activity', ['exception' => $e->getMessage()]);
|
||||
$latestForumActivity = collect();
|
||||
}
|
||||
|
||||
return view('web.home', compact(
|
||||
'page_title',
|
||||
|
||||
Reference in New Issue
Block a user