Added "any" search option for private images
This commit is contained in:
parent
dd08b936e3
commit
8e976fb812
1 changed files with 18 additions and 12 deletions
|
@ -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,20 +153,26 @@ 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 = "";
|
||||||
|
switch ($matches[1]) {
|
||||||
|
case "no":
|
||||||
|
$query .= "private = SCORE_BOOL_N";
|
||||||
|
break;
|
||||||
|
case "yes":
|
||||||
|
$query .= "private = SCORE_BOOL_Y";
|
||||||
|
|
||||||
if ($matches[1] == "no") {
|
// Admins can view others private images, but they have to specify the user
|
||||||
$query .= "SCORE_BOOL_N";
|
if (!$user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES) ||
|
||||||
} else {
|
!UserPage::has_user_query($event->context)) {
|
||||||
$query .= "SCORE_BOOL_Y";
|
$query .= " AND owner_id = :private_owner_id";
|
||||||
|
$params["private_owner_id"] = $user->id;
|
||||||
// Admins can view others private images, but they have to specify the user
|
}
|
||||||
if (!$user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES) ||
|
break;
|
||||||
!UserPage::has_user_query($event->context)) {
|
case "any":
|
||||||
$query .= " AND owner_id = :private_owner_id";
|
$query .= "private = SCORE_BOOL_N OR owner_id = :private_owner_id";
|
||||||
$params["private_owner_id"] = $user->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));
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue