Skip to content

Commit

Permalink
changed: no longer use OpenSearch in admin context
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Nov 29, 2024
1 parent f7c7fd4 commit 8fb3caa
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion classes/ColdTrick/OpenSearch/SearchEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function searchParams(\Elgg\Event $event): ?array {
return null;
}

if (!self::handleSearch() || self::detectUnsupportedSearchParams($search_params)) {
if (!self::handleSearch() || self::isInAdminContext() || self::detectUnsupportedSearchParams($search_params)) {
$search_params['_opensearch_supported'] = false;

return $search_params;
Expand Down Expand Up @@ -489,6 +489,26 @@ protected static function handleSearch(): bool {
return elgg_get_plugin_setting('search', 'opensearch') === 'yes';
}

/**
* Are we using the search in an admin context
*
* @return bool
*/
protected static function isInAdminContext(): bool {
if (elgg_in_context('admin')) {
return true;
}

if (elgg_is_xhr()) {
$referer = (string) _elgg_services()->request->headers->get('referer');
$admin = rtrim(elgg_generate_url('admin'), '/');

return str_starts_with($referer, $admin);
}

return false;
}

/**
* Get the search service
*
Expand All @@ -501,6 +521,10 @@ protected static function getServiceForEvents($params): ?SearchService {
return null;
}

if (self::isInAdminContext()) {
return null;
}

if (self::detectUnsupportedSearchParams($params)) {
return null;
}
Expand Down

0 comments on commit 8fb3caa

Please sign in to comment.