Added "any" search option for private images

This commit is contained in:
Matthew Barbour 2020-06-04 09:50:37 -05:00 committed by Shish
parent dd08b936e3
commit 8e976fb812

View File

@ -123,7 +123,7 @@ class PrivateImage extends Extension
} }
const SEARCH_REGEXP = "/^private:(yes|no)/"; const SEARCH_REGEXP = "/^private:(yes|no|any)/";
public function onSearchTermParse(SearchTermParseEvent $event) public function onSearchTermParse(SearchTermParseEvent $event)
{ {
global $user, $database, $user_config; global $user, $database, $user_config;
@ -153,13 +153,14 @@ class PrivateImage extends Extension
} }
if (preg_match(self::SEARCH_REGEXP, strtolower($event->term), $matches)) { if (preg_match(self::SEARCH_REGEXP, strtolower($event->term), $matches)) {
$query = "private = ";
$params = []; $params = [];
$query = "";
if ($matches[1] == "no") { switch ($matches[1]) {
$query .= "SCORE_BOOL_N"; case "no":
} else { $query .= "private = SCORE_BOOL_N";
$query .= "SCORE_BOOL_Y"; break;
case "yes":
$query .= "private = SCORE_BOOL_Y";
// Admins can view others private images, but they have to specify the user // Admins can view others private images, but they have to specify the user
if (!$user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES) || if (!$user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES) ||
@ -167,6 +168,11 @@ class PrivateImage extends Extension
$query .= " AND owner_id = :private_owner_id"; $query .= " AND owner_id = :private_owner_id";
$params["private_owner_id"] = $user->id; $params["private_owner_id"] = $user->id;
} }
break;
case "any":
$query .= "private = SCORE_BOOL_N OR owner_id = :private_owner_id";
$params["private_owner_id"] = $user->id;
break;
} }
$event->add_querylet(new Querylet($database->scoreql_to_sql($query), $params)); $event->add_querylet(new Querylet($database->scoreql_to_sql($query), $params));
} }