diff --git a/CHANGELOG-DEV.md b/CHANGELOG-DEV.md index ff0f21a8a5..8d137be23b 100644 --- a/CHANGELOG-DEV.md +++ b/CHANGELOG-DEV.md @@ -13,6 +13,7 @@ HumHub Changelog - Fix #6962: People filter - Hide follower options if Following is disabled in the User module - Fix #6961: Fix people dropdown filter without defined keys - Fix #6967: Use same order for meta searching that is used for content page searching by default +- Enh #6968: Meta search: open external links in new window 1.16.0-beta.2 (April 9, 2024) ----------------------------- diff --git a/protected/humhub/services/MetaSearchService.php b/protected/humhub/services/MetaSearchService.php index b30243dbff..3e36d2f795 100644 --- a/protected/humhub/services/MetaSearchService.php +++ b/protected/humhub/services/MetaSearchService.php @@ -81,6 +81,31 @@ public function getUrl(): string return Url::to($params); } + /** + * Get a link target depending on URL, + * external URLs should be opened in a new window + * + * @param string|null $url + * @return string|null + */ + public function getLinkTarget(?string $url = null): ?string + { + if ($url === null) { + $url = $this->getUrl(); + } + + if (!is_string($url) || Url::isRelative($url)) { + return null; + } + + $url = parse_url($url); + if (!isset($url['host']) || $url['host'] !== Yii::$app->request->hostName) { + return '_blank'; + } + + return null; + } + /** * Check if a searching has been done * diff --git a/protected/humhub/widgets/views/metaSearchProvider.php b/protected/humhub/widgets/views/metaSearchProvider.php index 6f3dda6cf2..661ecb56c2 100644 --- a/protected/humhub/widgets/views/metaSearchProvider.php +++ b/protected/humhub/widgets/views/metaSearchProvider.php @@ -23,13 +23,17 @@ getService()->isSearched()) : ?> getService()->hasResults()) : ?> getService()->getResults() as $record) : ?> - + $record->getUrl(), + 'class' => 'search-provider-record', + 'target' => $provider->getService()->getLinkTarget($record->getUrl()), + ]) ?> getImage() ?> getTitle() ?> getDescription() ?> - +
@@ -38,6 +42,7 @@ getAllResultsText()) ->link($provider->getService()->getUrl()) ->cssClass('search-provider-show-all') + ->options(['target' => $provider->getService()->getLinkTarget()]) ->loader(false) ?>