From 1aa07f87a44b50e93f25006c4007450834abda6f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 4 Mar 2020 22:20:28 +0100 Subject: [PATCH] Make "HTTPRequest::fetchUrl" dynamic --- mod/dfrn_poll.php | 5 ++--- mod/dfrn_request.php | 3 +-- mod/oexchange.php | 3 +-- src/Content/OEmbed.php | 7 +++---- src/Content/Text/BBCode.php | 7 +++---- src/Core/Protocol.php | 4 +--- src/Core/Search.php | 3 +-- src/Core/Worker.php | 3 +-- src/Model/GContact.php | 3 +-- src/Model/GServer.php | 3 +-- src/Model/User.php | 3 +-- src/Module/Debug/Feed.php | 3 +-- src/Network/HTTPRequest.php | 4 ++-- src/Protocol/Diaspora.php | 3 +-- src/Protocol/Salmon.php | 3 +-- src/Util/Images.php | 3 +-- src/Worker/CheckVersion.php | 3 +-- src/Worker/CronJobs.php | 3 +-- src/Worker/Directory.php | 3 +-- src/Worker/SearchDirectory.php | 3 +-- 20 files changed, 26 insertions(+), 46 deletions(-) diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 00732982ed..7f7fbe498f 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -25,7 +25,6 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Util\Strings; @@ -115,7 +114,7 @@ function dfrn_poll_init(App $a) ); if (DBA::isResult($r)) { - $s = HTTPRequest::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); + $s = DI::httpRequest()->fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); Logger::log("dfrn_poll: old profile returns " . $s, Logger::DATA); @@ -499,7 +498,7 @@ function dfrn_poll_content(App $a) // URL reply if ($dfrn_version < 2.2) { - $s = HTTPRequest::fetchUrl($r[0]['poll'] + $s = DI::httpRequest()->fetchUrl($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' . '&dfrn_version=' . DFRN_PROTOCOL_VERSION diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index bdc407b0b1..8c8557650e 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -39,7 +39,6 @@ use Friendica\Model\Notify\Type; use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Module\Security\Login; -use Friendica\Network\HTTPRequest; use Friendica\Network\Probe; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; @@ -204,7 +203,7 @@ function dfrn_request_post(App $a) } if (!empty($dfrn_request) && strlen($confirm_key)) { - HTTPRequest::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key); + DI::httpRequest()->fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key); } // (ignore reply, nothing we can do it failed) diff --git a/mod/oexchange.php b/mod/oexchange.php index 5238893320..4746651c16 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Module\Security\Login; -use Friendica\Network\HTTPRequest; use Friendica\Util\Strings; function oexchange_init(App $a) { @@ -58,7 +57,7 @@ function oexchange_content(App $a) { $tags = ((!empty($_REQUEST['tags'])) ? '&tags=' . urlencode(Strings::escapeTags(trim($_REQUEST['tags']))) : ''); - $s = HTTPRequest::fetchUrl(DI::baseUrl() . '/parse_url?url=' . $url . $title . $description . $tags); + $s = DI::httpRequest()->fetchUrl(DI::baseUrl() . '/parse_url?url=' . $url . $title . $description . $tags); if (!strlen($s)) { return; diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 8cfb8ce0a1..592d25c10d 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -31,7 +31,6 @@ use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\ParseUrl; @@ -96,7 +95,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery - $html_text = HTTPRequest::fetchUrl($embedurl, false, 15, 'text/*'); + $html_text = DI::httpRequest()->fetchUrl($embedurl, false, 15, 'text/*'); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -104,14 +103,14 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode('href')->nodeValue; - $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth); + $json_string = DI::httpRequest()->fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode('href')->nodeValue; - $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth); + $json_string = DI::httpRequest()->fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f03ea6104b..9d9679c494 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -38,7 +38,6 @@ use Friendica\Model\Contact; use Friendica\Model\Event; use Friendica\Model\Photo; use Friendica\Model\Tag; -use Friendica\Network\HTTPRequest; use Friendica\Object\Image; use Friendica\Protocol\Activity; use Friendica\Util\Images; @@ -486,7 +485,7 @@ class BBCode continue; } - $curlResult = HTTPRequest::curl($mtch[1], true); + $curlResult = DI::httpRequest()->curl($mtch[1], true); if (!$curlResult->isSuccess()) { continue; } @@ -1107,7 +1106,7 @@ class BBCode $text = "[url=" . $match[2] . ']' . $match[2] . "[/url]"; // if its not a picture then look if its a page that contains a picture link - $body = HTTPRequest::fetchUrl($match[1]); + $body = DI::httpRequest()->fetchUrl($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); @@ -1186,7 +1185,7 @@ class BBCode } // if its not a picture then look if its a page that contains a picture link - $body = HTTPRequest::fetchUrl($match[1]); + $body = DI::httpRequest()->fetchUrl($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); diff --git a/src/Core/Protocol.php b/src/Core/Protocol.php index 84b589bf29..e6133240c4 100644 --- a/src/Core/Protocol.php +++ b/src/Core/Protocol.php @@ -21,8 +21,6 @@ namespace Friendica\Core; -use Friendica\Network\HTTPRequest; - /** * Manage compatibility with federated networks */ @@ -123,7 +121,7 @@ class Protocol if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) { $statusnet_host = $matches[1]; $statusnet_user = $matches[2]; - $UserData = HTTPRequest::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); + $UserData = DI::httpRequest()->fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); $user = json_decode($UserData); if ($user) { $matches[2] = $user->screen_name; diff --git a/src/Core/Search.php b/src/Core/Search.php index aafa4024a8..768a0bf275 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -26,7 +26,6 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Network\HTTPException; -use Friendica\Network\HTTPRequest; use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ResultList; use Friendica\Util\Network; @@ -124,7 +123,7 @@ class Search $searchUrl .= '&page=' . $page; } - $resultJson = HTTPRequest::fetchUrl($searchUrl, false, 0, 'application/json'); + $resultJson = DI::httpRequest()->fetchUrl($searchUrl, false, 0, 'application/json'); $results = json_decode($resultJson, true); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index a5c4226c47..83a24c38fe 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -25,7 +25,6 @@ use Friendica\Core; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Process; -use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; /** @@ -997,7 +996,7 @@ class Worker } $url = DI::baseUrl() . '/worker'; - HTTPRequest::fetchUrl($url, false, 1); + DI::httpRequest()->fetchUrl($url, false, 1); } /** diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 669bc60c5d..dabc907f89 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -31,7 +31,6 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; use Friendica\Network\Probe; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\PortableContact; @@ -537,7 +536,7 @@ class GContact $done[] = DI::baseUrl() . '/poco'; if (strlen(DI::config()->get('system', 'directory'))) { - $x = HTTPRequest::fetchUrl(Search::getGlobalDirectory() . '/pubsites'); + $x = DI::httpRequest()->fetchUrl(Search::getGlobalDirectory() . '/pubsites'); if (!empty($x)) { $j = json_decode($x); if (!empty($j->entries)) { diff --git a/src/Model/GServer.php b/src/Model/GServer.php index c868e19d40..76082fe1ff 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -31,7 +31,6 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\Register; use Friendica\Network\CurlResult; -use Friendica\Network\HTTPRequest; use Friendica\Protocol\Diaspora; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; @@ -1635,7 +1634,7 @@ class GServer $protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus']; foreach ($protocols as $protocol) { $query = '{nodes(protocol:"' . $protocol . '"){host}}'; - $curlResult = HTTPRequest::fetchUrl('https://the-federation.info/graphql?query=' . urlencode($query)); + $curlResult = DI::httpRequest()->fetchUrl('https://the-federation.info/graphql?query=' . urlencode($query)); if (!empty($curlResult)) { $data = json_decode($curlResult, true); if (!empty($data['data']['nodes'])) { diff --git a/src/Model/User.php b/src/Model/User.php index fda105687d..9980c48d5a 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -34,7 +34,6 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\TwoFactor\AppSpecificPassword; use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Network\HTTPRequest; use Friendica\Object\Image; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; @@ -824,7 +823,7 @@ class User $photo_failure = false; $filename = basename($photo); - $curlResult = HTTPRequest::curl($photo, true); + $curlResult = DI::httpRequest()->curl($photo, true); if ($curlResult->isSuccess()) { $img_str = $curlResult->getBody(); $type = $curlResult->getContentType(); diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index 6214b49dd5..deeb8d7ec3 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -25,7 +25,6 @@ use Friendica\BaseModule; use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model; -use Friendica\Network\HTTPRequest; use Friendica\Protocol; /** @@ -49,7 +48,7 @@ class Feed extends BaseModule $contact = Model\Contact::getByURLForUser($url, local_user(), false); - $xml = HTTPRequest::fetchUrl($contact['poll']); + $xml = DI::httpRequest()->fetchUrl($contact['poll']); $import_result = Protocol\Feed::import($xml); diff --git a/src/Network/HTTPRequest.php b/src/Network/HTTPRequest.php index 14395c37f3..eaef6966d7 100644 --- a/src/Network/HTTPRequest.php +++ b/src/Network/HTTPRequest.php @@ -341,9 +341,9 @@ class HTTPRequest * @return string The fetched content * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) + public function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) { - $ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects); + $ret = $this->fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects); return $ret->getBody(); } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index ed369a3047..5e1f096773 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -41,7 +41,6 @@ use Friendica\Model\Mail; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPRequest; use Friendica\Network\Probe; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; @@ -1380,7 +1379,7 @@ class Diaspora Logger::log("Fetch post from ".$source_url, Logger::DEBUG); - $envelope = HTTPRequest::fetchUrl($source_url); + $envelope = DI::httpRequest()->fetchUrl($source_url); if ($envelope) { Logger::log("Envelope was fetched.", Logger::DEBUG); $x = self::verifyMagicEnvelope($envelope); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 35707b6356..921c060f88 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -22,7 +22,6 @@ namespace Friendica\Protocol; use Friendica\Core\Logger; -use Friendica\Network\HTTPRequest; use Friendica\Network\Probe; use Friendica\Util\Crypto; use Friendica\Util\Strings; @@ -72,7 +71,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (Strings::normaliseLink($ret[$x]) == 'http://') { - $ret[$x] = HTTPRequest::fetchUrl($ret[$x]); + $ret[$x] = DI::httpRequest()->fetchUrl($ret[$x]); } } } diff --git a/src/Util/Images.php b/src/Util/Images.php index 9e3be4f4f9..2d161a5c43 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -24,7 +24,6 @@ namespace Friendica\Util; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\DI; -use Friendica\Network\HTTPRequest; /** * Image utilities @@ -185,7 +184,7 @@ class Images return $data; } - $img_str = HTTPRequest::fetchUrl($url, true, 4); + $img_str = DI::httpRequest()->fetchUrl($url, true, 4); if (!$img_str) { return []; diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index f0369daab3..260d6b16f2 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -24,7 +24,6 @@ namespace Friendica\Worker; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; /** * Check the git repository VERSION file and save the version to the DB @@ -55,7 +54,7 @@ class CheckVersion Logger::log("Checking VERSION from: ".$checked_url, Logger::DEBUG); // fetch the VERSION file - $gitversion = DBA::escape(trim(HTTPRequest::fetchUrl($checked_url))); + $gitversion = DBA::escape(trim(DI::httpRequest()->fetchUrl($checked_url))); Logger::log("Upstream VERSION is: ".$gitversion, Logger::DEBUG); DI::config()->set('system', 'git_friendica_version', $gitversion); diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 23434beb14..1e45058569 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -33,7 +33,6 @@ use Friendica\Model\GContact; use Friendica\Model\Nodeinfo; use Friendica\Model\Photo; use Friendica\Model\User; -use Friendica\Network\HTTPRequest; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; @@ -61,7 +60,7 @@ class CronJobs // Now trying to register $url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname(); Logger::debug('Check registering url', ['url' => $url]); - $ret = HTTPRequest::fetchUrl($url); + $ret = DI::httpRequest()->fetchUrl($url); Logger::debug('Check registering answer', ['answer' => $ret]); Logger::info('cron_end'); break; diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index 0dea9841f0..2cab09f339 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -26,7 +26,6 @@ use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; /** * Sends updated profile data to the directory @@ -54,7 +53,7 @@ class Directory Logger::log('Updating directory: ' . $arr['url'], Logger::DEBUG); if (strlen($arr['url'])) { - HTTPRequest::fetchUrl($dir . '?url=' . bin2hex($arr['url'])); + DI::httpRequest()->fetchUrl($dir . '?url=' . bin2hex($arr['url'])); } return; diff --git a/src/Worker/SearchDirectory.php b/src/Worker/SearchDirectory.php index 1dcf0c8db6..c3c344d93c 100644 --- a/src/Worker/SearchDirectory.php +++ b/src/Worker/SearchDirectory.php @@ -30,7 +30,6 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\GServer; -use Friendica\Network\HTTPRequest; use Friendica\Util\Strings; class SearchDirectory @@ -52,7 +51,7 @@ class SearchDirectory } } - $x = HTTPRequest::fetchUrl(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search)); + $x = DI::httpRequest()->fetchUrl(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search)); $j = json_decode($x); if (!empty($j->results)) { -- 2.39.5