gallery fix
This commit is contained in:
@@ -8,6 +8,8 @@ use App\Models\Artwork;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Pagination\AbstractPaginator;
|
||||
use Illuminate\Pagination\AbstractCursorPaginator;
|
||||
|
||||
class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
@@ -23,6 +25,7 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
$perPage = $this->resolvePerPage($request);
|
||||
|
||||
$artworks = $this->artworks->browsePublicArtworks($perPage, $sort);
|
||||
$seo = $this->buildPaginationSeo($request, url('/browse'), $artworks);
|
||||
|
||||
$mainCategories = $this->mainCategories();
|
||||
|
||||
@@ -39,7 +42,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
'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',
|
||||
'page_canonical' => url('/browse'),
|
||||
'page_canonical' => $seo['canonical'],
|
||||
'page_rel_prev' => $seo['prev'],
|
||||
'page_rel_next' => $seo['next'],
|
||||
'page_robots' => 'index,follow',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -64,6 +70,7 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
$normalizedPath = trim((string) $path, '/');
|
||||
if ($normalizedPath === '') {
|
||||
$artworks = $this->artworks->getArtworksByContentType($contentSlug, $perPage, $sort);
|
||||
$seo = $this->buildPaginationSeo($request, url('/' . $contentSlug), $artworks);
|
||||
|
||||
return view('gallery.index', [
|
||||
'gallery_type' => 'content-type',
|
||||
@@ -78,7 +85,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
'page_title' => $contentType->name,
|
||||
'page_meta_description' => $contentType->description ?? ($contentType->name . ' artworks on Skinbase'),
|
||||
'page_meta_keywords' => strtolower($contentType->slug) . ', skinbase, artworks, wallpapers, skins, photography',
|
||||
'page_canonical' => url('/' . $contentSlug),
|
||||
'page_canonical' => $seo['canonical'],
|
||||
'page_rel_prev' => $seo['prev'],
|
||||
'page_rel_next' => $seo['next'],
|
||||
'page_robots' => 'index,follow',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -89,6 +99,7 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
}
|
||||
|
||||
$artworks = $this->artworks->getArtworksByCategoryPath(array_merge([$contentSlug], $segments), $perPage, $sort);
|
||||
$seo = $this->buildPaginationSeo($request, url('/' . $contentSlug . '/' . strtolower($category->full_slug_path)), $artworks);
|
||||
|
||||
$subcategories = $category->children()->orderBy('sort_order')->orderBy('name')->get();
|
||||
if ($subcategories->isEmpty()) {
|
||||
@@ -116,7 +127,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
'page_title' => $category->name,
|
||||
'page_meta_description' => $category->description ?? ($contentType->name . ' artworks on Skinbase'),
|
||||
'page_meta_keywords' => strtolower($contentType->slug) . ', skinbase, artworks, wallpapers, skins, photography',
|
||||
'page_canonical' => url('/' . $contentSlug . '/' . strtolower($category->full_slug_path)),
|
||||
'page_canonical' => $seo['canonical'],
|
||||
'page_rel_prev' => $seo['prev'],
|
||||
'page_rel_next' => $seo['next'],
|
||||
'page_robots' => 'index,follow',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -180,7 +194,10 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
|
||||
private function resolvePerPage(Request $request): int
|
||||
{
|
||||
$value = (int) $request->query('per_page', 40);
|
||||
$limit = (int) $request->query('limit', 0);
|
||||
$perPage = (int) $request->query('per_page', 0);
|
||||
|
||||
$value = $limit > 0 ? $limit : ($perPage > 0 ? $perPage : 40);
|
||||
|
||||
return max(12, min($value, 80));
|
||||
}
|
||||
@@ -198,4 +215,79 @@ class BrowseGalleryController extends \App\Http\Controllers\Controller
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
private function buildPaginationSeo(Request $request, string $canonicalBaseUrl, mixed $paginator): array
|
||||
{
|
||||
$canonicalQuery = $request->query();
|
||||
unset($canonicalQuery['grid']);
|
||||
if (($canonicalQuery['page'] ?? null) !== null && (int) $canonicalQuery['page'] <= 1) {
|
||||
unset($canonicalQuery['page']);
|
||||
}
|
||||
|
||||
$canonical = $canonicalBaseUrl;
|
||||
if ($canonicalQuery !== []) {
|
||||
$canonical .= '?' . http_build_query($canonicalQuery);
|
||||
}
|
||||
|
||||
$prev = null;
|
||||
$next = null;
|
||||
|
||||
if ($paginator instanceof AbstractPaginator || $paginator instanceof AbstractCursorPaginator) {
|
||||
$prev = $this->stripQueryParamFromUrl($paginator->previousPageUrl(), 'grid');
|
||||
$next = $this->stripQueryParamFromUrl($paginator->nextPageUrl(), 'grid');
|
||||
}
|
||||
|
||||
return [
|
||||
'canonical' => $canonical,
|
||||
'prev' => $prev,
|
||||
'next' => $next,
|
||||
];
|
||||
}
|
||||
|
||||
private function stripQueryParamFromUrl(?string $url, string $queryParam): ?string
|
||||
{
|
||||
if ($url === null || $url === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parts = parse_url($url);
|
||||
if (!is_array($parts)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$query = [];
|
||||
if (!empty($parts['query'])) {
|
||||
parse_str($parts['query'], $query);
|
||||
unset($query[$queryParam]);
|
||||
}
|
||||
|
||||
$rebuilt = '';
|
||||
if (isset($parts['scheme'])) {
|
||||
$rebuilt .= $parts['scheme'] . '://';
|
||||
}
|
||||
if (isset($parts['user'])) {
|
||||
$rebuilt .= $parts['user'];
|
||||
if (isset($parts['pass'])) {
|
||||
$rebuilt .= ':' . $parts['pass'];
|
||||
}
|
||||
$rebuilt .= '@';
|
||||
}
|
||||
if (isset($parts['host'])) {
|
||||
$rebuilt .= $parts['host'];
|
||||
}
|
||||
if (isset($parts['port'])) {
|
||||
$rebuilt .= ':' . $parts['port'];
|
||||
}
|
||||
$rebuilt .= $parts['path'] ?? '';
|
||||
|
||||
if ($query !== []) {
|
||||
$rebuilt .= '?' . http_build_query($query);
|
||||
}
|
||||
|
||||
if (isset($parts['fragment'])) {
|
||||
$rebuilt .= '#' . $parts['fragment'];
|
||||
}
|
||||
|
||||
return $rebuilt;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user