]> git.mxchange.org Git - friendica.git/commitdiff
Make "HTTPRequest::fetchUrl" dynamic
authornupplaPhil <admin+github@philipp.info>
Wed, 4 Mar 2020 21:20:28 +0000 (22:20 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 21 Jul 2020 07:04:58 +0000 (03:04 -0400)
20 files changed:
mod/dfrn_poll.php
mod/dfrn_request.php
mod/oexchange.php
src/Content/OEmbed.php
src/Content/Text/BBCode.php
src/Core/Protocol.php
src/Core/Search.php
src/Core/Worker.php
src/Model/GContact.php
src/Model/GServer.php
src/Model/User.php
src/Module/Debug/Feed.php
src/Network/HTTPRequest.php
src/Protocol/Diaspora.php
src/Protocol/Salmon.php
src/Util/Images.php
src/Worker/CheckVersion.php
src/Worker/CronJobs.php
src/Worker/Directory.php
src/Worker/SearchDirectory.php

index 00732982ed8b77a07192cff2f212a5384bc42034..7f7fbe498f8ff39e6ad9ae04055f133c660aa65e 100644 (file)
@@ -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
index bdc407b0b14aaab13725b2b97ff7c8835f72e705..8c8557650ed55efd3a8831688c976a246ad444f8 100644 (file)
@@ -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)
index 523889332013fa038aa0587b62f5a5e337e49b86..4746651c16985262ff3732bc00deac1ac8d9cc65 100644 (file)
@@ -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;
index 8cfb8ce0a129e5249a4a61240621db716d1373cf..592d25c10d249bb00de2a8c4d28de077ab1e1a74 100644 (file)
@@ -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;
                                                }
                                        }
index f03ea6104b4c276e53fd88d9b0b14ec5e75ffe53..9d9679c4940462ecb004c5f7059c49789a3e9b8e 100644 (file)
@@ -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);
index 84b589bf2913eb7c842cd74cfb369dbe788c5cb6..e6133240c4dacc2c233341a385575f24ceb922ee 100644 (file)
@@ -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;
index aafa4024a899315e509ca324d87794d3457e8b10..768a0bf27570366298a750e2d865cb9a2fd54510 100644 (file)
@@ -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);
 
index a5c4226c47ab5c9949bf99b8630dc13ad37fdaa2..83a24c38fe79cbd1e9665358d571df5c51549df9 100644 (file)
@@ -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);
        }
 
        /**
index 669bc60c5d76afe084d9d71b35108b0aae237447..dabc907f89ce84895094e1f50a667576e9f90490 100644 (file)
@@ -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)) {
index c868e19d40c899decea0ab43ee4983ae3f9e81bc..76082fe1ff9754a73ecc599e54dd47d758781f3f 100644 (file)
@@ -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'])) {
index fda105687d2f240cafcbdbd8b51db817cbac0b84..9980c48d5aeeaaa2af4d5455da6305e343b2763d 100644 (file)
@@ -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();
index 6214b49dd5296a803c6175a9759181d47be6de53..deeb8d7ec350fdc241df79090584466ce0a6fe35 100644 (file)
@@ -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);
 
index 14395c37f3237c2ca3e1b2d0e87e59d333e2d0e1..eaef6966d73035612e0c036f55ac697df4a9b523 100644 (file)
@@ -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();
        }
index ed369a3047336972bbe4ce8572fc5da9804350f4..5e1f09677375b5690e77acbb742a01960c4415b1 100644 (file)
@@ -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);
index 35707b63567c5acaf048c9f0b437f38d8269cf71..921c060f8867f2e0ce058a410ab14853c8acc22f 100644 (file)
@@ -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]);
                                }
                        }
                }
index 9e3be4f4f902f3425c38cf8ddf05b1a453898756..2d161a5c43232e8e3590dff6021dd3343f13a173 100644 (file)
@@ -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 [];
index f0369daab3eb3738577f47e30c1aa2e9e485ea62..260d6b16f25898d230486913d1c2758f6312e1a9 100644 (file)
@@ -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);
index 23434beb14049009f724dc2aa3931323e8b0a0d5..1e450585694a81df4f25d35845ef221db95ab139 100644 (file)
@@ -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;
index 0dea9841f06e7ff3c74b13c6ae3fb2606f6e30ce..2cab09f3392fc7ebe497a277974e04fc6a139235 100644 (file)
@@ -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;
index 1dcf0c8db6bb4990cdc08cc35235aaeb50686af9..c3c344d93caf077afe47f1e80588c6d8df9b8212 100644 (file)
@@ -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)) {