Make "HTTPRequest::fetchUrl" dynamic

pull/8911/head
nupplaPhil 2020-03-04 22:20:28 +01:00 zatwierdzone przez Hypolite Petovan
rodzic 3b4cf87c95
commit 1aa07f87a4
20 zmienionych plików z 26 dodań i 46 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;
}
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -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;

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);
}
/**

Wyświetl plik

@ -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)) {

Wyświetl plik

@ -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'])) {

Wyświetl plik

@ -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();

Wyświetl plik

@ -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);

Wyświetl plik

@ -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();
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -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]);
}
}
}

Wyświetl plik

@ -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 [];

Wyświetl plik

@ -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);

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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)) {