From 1c66d49599503355147d0eb25b43515c52c6b0e7 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 May 2024 21:47:57 +0000 Subject: [PATCH] "Network::unparseURL" is replaced with "Uri::fromParts" --- src/Content/BoundariesPager.php | 4 +-- src/Content/ContactSelector.php | 4 +-- src/Content/Text/HTML.php | 4 +-- src/Model/PushSubscriber.php | 4 +-- src/Module/Api/Mastodon/Instance/Peers.php | 4 +-- src/Network/HTTPClient/Client/HttpClient.php | 3 +- .../HTTPClient/Response/CurlResult.php | 5 ++- src/Network/Probe.php | 2 +- src/Util/Network.php | 36 ++----------------- 9 files changed, 17 insertions(+), 49 deletions(-) diff --git a/src/Content/BoundariesPager.php b/src/Content/BoundariesPager.php index 51838f0536..76b387675e 100644 --- a/src/Content/BoundariesPager.php +++ b/src/Content/BoundariesPager.php @@ -23,8 +23,8 @@ namespace Friendica\Content; use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\Util\Network; use Friendica\Util\Strings; +use GuzzleHttp\Psr7\Uri; /** * This pager should be used by lists using the min_id†/max_id† parameters @@ -67,7 +67,7 @@ class BoundariesPager extends Pager $parsed['query'] = http_build_query($queryParameters); - $url = Network::unparseURL($parsed); + $url = (string)Uri::fromParts((array)$parsed); $this->setQueryString($url); } diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index 1568e3a2fd..ed23151e60 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -25,8 +25,8 @@ use Friendica\Core\Hook; use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Util\Network; use Friendica\Util\Strings; +use GuzzleHttp\Psr7\Uri; /** * ContactSelector class @@ -102,7 +102,7 @@ class ContactSelector // Create the server url out of the profile url $parts = parse_url($profile); unset($parts['path']); - $server_url = Strings::normaliseLink(Network::unparseURL($parts)); + $server_url = Strings::normaliseLink((string)Uri::fromParts((array)$parts)); } self::$server_url[$profile] = $server_url; diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index f3be678f9d..587c608de9 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -29,9 +29,9 @@ use Friendica\Core\Renderer; use Friendica\Core\Search; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\XML; +use GuzzleHttp\Psr7\Uri; use League\HTMLToMarkdown\HtmlConverter; use Psr\Http\Message\UriInterface; @@ -407,7 +407,7 @@ class HTML } $parts = array_merge($base, parse_url($url)); - $url2 = Network::unparseURL($parts); + $url2 = (string)Uri::fromParts((array)$parts); return str_replace($url, $url2, $link); } diff --git a/src/Model/PushSubscriber.php b/src/Model/PushSubscriber.php index e910f2f1e1..42cb39596c 100644 --- a/src/Model/PushSubscriber.php +++ b/src/Model/PushSubscriber.php @@ -25,7 +25,7 @@ use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; +use GuzzleHttp\Psr7\Uri; class PushSubscriber { @@ -179,7 +179,7 @@ class PushSubscriber $parts = parse_url($subscriber['callback_url']); unset($parts['path']); - $server_url = Network::unparseURL($parts); + $server_url = (string)Uri::fromParts((array)$parts); $gsid = GServer::getID($server_url, true); if (!empty($gsid)) { GServer::setProtocol($gsid, Post\DeliveryData::OSTATUS); diff --git a/src/Module/Api/Mastodon/Instance/Peers.php b/src/Module/Api/Mastodon/Instance/Peers.php index 4bfde07c2d..4c17791f5f 100644 --- a/src/Module/Api/Mastodon/Instance/Peers.php +++ b/src/Module/Api/Mastodon/Instance/Peers.php @@ -26,7 +26,7 @@ use Friendica\Database\DBA; use Friendica\Model\GServer; use Friendica\Module\BaseApi; use Friendica\Network\HTTPException; -use Friendica\Util\Network; +use GuzzleHttp\Psr7\Uri; /** * Undocumented API endpoint that is implemented by both Mastodon and Pleroma @@ -47,7 +47,7 @@ class Peers extends BaseApi while ($instance = DBA::fetch($instances)) { $urldata = parse_url($instance['url']); unset($urldata['scheme']); - $return[] = ltrim(Network::unparseURL($urldata), '/'); + $return[] = ltrim((string)Uri::fromParts((array)$urldata), '/'); } DBA::close($instances); diff --git a/src/Network/HTTPClient/Client/HttpClient.php b/src/Network/HTTPClient/Client/HttpClient.php index f6669a20bf..8613166a28 100644 --- a/src/Network/HTTPClient/Client/HttpClient.php +++ b/src/Network/HTTPClient/Client/HttpClient.php @@ -33,6 +33,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Cookie\FileCookieJar; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\TransferException; +use GuzzleHttp\Psr7\Uri; use GuzzleHttp\RequestOptions; use mattwright\URLResolver; use Psr\Http\Message\ResponseInterface; @@ -104,7 +105,7 @@ class HttpClient implements ICanSendHttpRequests } } $parts['path'] = implode('/', $parts2); - $url = Network::unparseURL($parts); + $url = (string)Uri::fromParts((array)$parts); if (Network::isUrlBlocked($url)) { $this->logger->info('Domain is blocked.', ['url' => $url]); diff --git a/src/Network/HTTPClient/Response/CurlResult.php b/src/Network/HTTPClient/Response/CurlResult.php index 561c8c47ab..75d390eac7 100644 --- a/src/Network/HTTPClient/Response/CurlResult.php +++ b/src/Network/HTTPClient/Response/CurlResult.php @@ -21,10 +21,9 @@ namespace Friendica\Network\HTTPClient\Response; -use Friendica\Core\Logger; use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPException\UnprocessableEntityException; -use Friendica\Util\Network; +use GuzzleHttp\Psr7\Uri; use Psr\Log\LoggerInterface; /** @@ -224,7 +223,7 @@ class CurlResult implements ICanHandleHttpResponses } } - $this->redirectUrl = Network::unparseURL($redirect_parts); + $this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts); $this->isRedirectUrl = true; } else { diff --git a/src/Network/Probe.php b/src/Network/Probe.php index a0f1a85a47..77a25dac4b 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1660,7 +1660,7 @@ class Probe unset($baseParts['query']); unset($baseParts['fragment']); - return Network::unparseURL((array)$baseParts); + return (string)Uri::fromParts((array)(array)$baseParts); } /** diff --git a/src/Util/Network.php b/src/Util/Network.php index 54eb13bd12..fe376ce5c8 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -400,7 +400,7 @@ class Network ]; $parts = array_merge($base, parse_url('/' . ltrim($url, '/'))); - return self::unparseURL($parts); + return (string)Uri::fromParts((array)$parts); } /** @@ -492,38 +492,6 @@ class Network return Strings::normaliseLink($match); } - /** - * Glue url parts together - * - * @param array $parsed URL parts - * - * @return string|null The glued URL or null on error - * @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead - */ - public static function unparseURL(array $parsed): string - { - $get = function ($key) use ($parsed) { - return isset($parsed[$key]) ? $parsed[$key] : null; - }; - - $pass = $get('pass'); - $user = $get('user'); - $userinfo = $pass !== null ? "$user:$pass" : $user; - $port = $get('port'); - $scheme = $get('scheme'); - $query = $get('query'); - $fragment = $get('fragment'); - $authority = ($userinfo !== null ? $userinfo . '@' : '') . - $get('host') . - ($port ? ":$port" : ''); - - return (!empty($scheme) ? $scheme . ':' : '') . - (!empty($authority) ? '//' . $authority : '') . - $get('path') . - (!empty($query) ? '?' . $query : '') . - (!empty($fragment) ? '#' . $fragment : ''); - } - /** * Convert an URI to an IDN compatible URI * @@ -602,7 +570,7 @@ class Network $parsed['query'] = http_build_query($params); - return self::unparseURL($parsed); + return (string)Uri::fromParts((array)$parsed); } /**