From: Hypolite Petovan Date: Tue, 25 Jul 2023 21:13:01 +0000 (+0200) Subject: Add new BaseUrl->isLocalUri and BaseUrl->isLocalUrl methods X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=148c1c7e1a17b70ff9b75e5dd68ca63e1328843f;p=friendica.git Add new BaseUrl->isLocalUri and BaseUrl->isLocalUrl methods - Deprecate Util\Network->isLocalLink to reduce dependency on DI class --- diff --git a/src/App/BaseURL.php b/src/App/BaseURL.php index 4030306849..cc20343d1c 100644 --- a/src/App/BaseURL.php +++ b/src/App/BaseURL.php @@ -127,4 +127,14 @@ class BaseURL extends Uri implements UriInterface $redirectTo = $this->__toString() . '/' . ltrim($toUrl, '/'); System::externalRedirect($redirectTo); } + + public function isLocalUrl(string $url): bool + { + return strpos(Strings::normaliseLink($url), Strings::normaliseLink((string)$this)) === 0; + } + + public function isLocalUri(UriInterface $uri): bool + { + return $this->isLocalUrl((string)$uri); + } } diff --git a/src/Util/Network.php b/src/Util/Network.php index f7ceab5433..495510189f 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -640,10 +640,11 @@ class Network * @param string $url * * @return bool + * @deprecated since 2023.09, please use BaseUrl->isLocalUrl or BaseUrl->isLocalUri instead. */ public static function isLocalLink(string $url): bool { - return (strpos(Strings::normaliseLink($url), Strings::normaliseLink(DI::baseUrl())) !== false); + return DI::baseUrl()->isLocalUrl($url); } /**