ViewPhoto: simplify filter verification

This commit is contained in:
Aaron van Geffen 2024-01-15 11:33:43 +01:00
parent 52472d8b58
commit ec2d702a0d
3 changed files with 9 additions and 6 deletions

View File

@ -50,13 +50,12 @@ class ViewPhoto extends HTMLController
if (isset($_GET['by'])) if (isset($_GET['by']))
{ {
// Let's first verify that the filter is valid // Let's first verify that the filter is valid
$contributors = array_filter($tag->getContributorList(), fn($el) => $el['slug'] === $_GET['by']); $user = Member::fromSlug($_GET['by']);
if (count($contributors) !== 1) if (!$user)
throw new UnexpectedValueException('Invalid filter for this album or tag.'); throw new UnexpectedValueException('Invalid filter for this album or tag.');
// Alright, let's run with it then // Alright, let's run with it then
$filter = reset($contributors); $page->setActiveFilter($user->getSlug());
$page->setActiveFilter($filter['slug']);
} }
$this->page->adopt($page); $this->page->adopt($page);

View File

@ -723,9 +723,8 @@ class Asset
} }
// Take active filter into account as well // Take active filter into account as well
if (!empty($activeFilter)) if (!empty($activeFilter) && ($user = Member::fromSlug($activeFilter)) !== false)
{ {
$user = Member::fromSlug($activeFilter);
$where[] = 'id_user_uploaded = {int:id_user_uploaded}'; $where[] = 'id_user_uploaded = {int:id_user_uploaded}';
$params['id_user_uploaded'] = $user->getUserId(); $params['id_user_uploaded'] = $user->getUserId();
} }

View File

@ -75,6 +75,11 @@ abstract class User
return $this->ip_address; return $this->ip_address;
} }
public function getSlug()
{
return $this->slug;
}
/** /**
* Returns whether user is logged in. * Returns whether user is logged in.
*/ */