// Privacy layer
if (
!($this->requester['is_admin'] ?? false)
&& in_array($this->type, ['images', 'albums', 'users'])
&& (
(!isset($this->owner) || !isset($this->requester)) || $this->owner !== $this->requester['id']
)
) {
if (empty($this->where)) {
$this->where = 'WHERE ';
} else {
$this->where .= ' AND ';
}
$nsfw_off = $this->requester ? !$this->requester['show_nsfw_listings'] : !getSetting('show_nsfw_in_listings');
switch ($this->type) {
case 'images':
if ($nsfw_off) {
$nsfw_off_clause = $tables['images'] . '.image_nsfw = 0';
if ($this->requester) {
$this->where .= '(' . $nsfw_off_clause . ' OR (' . $tables['images'] . '.image_nsfw = 1 AND ' . $tables['images'] . '.image_user_id = ' . $this->requester['id'] . ')) AND ';
} else {
$this->where .= $nsfw_off_clause . ' AND ';
}
}
break;
case 'users':
$this->where .= $tables['users'] . '.user_is_private = 0';
break;
}
if ($this->type !== 'users') {
if (getSetting('website_privacy_mode') == 'public' || $this->privacy == 'private_but_link' || getSetting('website_content_privacy_mode') == 'default') {
$this->where .= '(' . $tables['albums'] . '.album_privacy NOT IN';
$privacy_modes = ['private', 'private_but_link', 'password', 'custom'];
if (in_array($this->privacy, $privacy_modes)) {
unset($privacy_modes[array_search($this->privacy, $privacy_modes)]);
}
$this->where .= " (" . "'" . implode("','", $privacy_modes) . "'" . ") ";
$this->where .= "OR " . $tables['albums'] . '.album_privacy IS NULL';
if ($this->requester) {
$this->where .= ' OR ' . $tables['albums'] . '.album_user_id =' . $this->requester['id'];
}
$this->where .= ')';
} else {
$injected_requester = !$this->requester['id'] ? 0 : $this->requester['id'];
$this->where .= '(' . $tables['albums'] . '.album_user_id = ' . $injected_requester;
$this->where .= $this->type == 'albums' ? ')' : (' OR ' . $tables['images'] . '.image_user_id = ' . $injected_requester . ')');
}
}
}