From 2f9642392dcd40fd6d949d607c0cafa337d4637e Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:18:38 -0500 Subject: [PATCH] Move z_fetch_url move z_fetch_url method --- include/acl_selectors.php | 3 ++- include/network.php | 10 ------- mod/ostatus_subscribe.php | 3 ++- mod/parse_url.php | 3 ++- src/Model/GContact.php | 2 +- src/Network/Probe.php | 17 ++++++------ src/Protocol/DFRN.php | 3 ++- src/Protocol/OStatus.php | 15 ++++++----- src/Protocol/PortableContact.php | 46 ++++++++++++++++---------------- src/Util/ExAuth.php | 4 +-- src/Util/Network.php | 2 +- src/Util/ParseUrl.php | 3 ++- src/Worker/DiscoverPoCo.php | 2 +- src/Worker/OnePoll.php | 5 ++-- 14 files changed, 58 insertions(+), 60 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 599b543ad0..38a418dd1c 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -11,6 +11,7 @@ use Friendica\Core\L10n; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; +use Friendica\Util\Network; require_once "mod/proxy.php"; @@ -733,7 +734,7 @@ function navbar_complete(App $a) { if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = z_fetch_url(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::zFetchURL(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); if ($x['success']) { $j = json_decode($x['body'],true); if ($j && isset($j['results'])) { diff --git a/include/network.php b/include/network.php index f6a864a635..7f1bbb6d83 100644 --- a/include/network.php +++ b/include/network.php @@ -12,16 +12,6 @@ use Friendica\Object\Image; use Friendica\Util\Network; use Friendica\Util\XML; -function fetch_url($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) -{ - return Network::fetchURL($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); -} - -function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = []) -{ - return Network::zFetchURL($url, $binary, $redirects, $opts); -} - function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) { return Network::postURL($url, $params, $headers, $redirects, $timeout); diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 295ccfee61..81eced22e7 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -8,6 +8,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Model\Contact; use Friendica\Network\Probe; +use Friendica\Util\Network; function ostatus_subscribe_content(App $a) { @@ -40,7 +41,7 @@ function ostatus_subscribe_content(App $a) { $api = $contact["baseurl"]."/api/"; // Fetching friends - $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]); + $data = Network::zFetchURL($api."statuses/friends.json?screen_name=".$contact["nick"]); if (!$data["success"]) { return $o.L10n::t("Couldn't fetch friends for contact."); diff --git a/mod/parse_url.php b/mod/parse_url.php index 6fb404f1b0..f1214e160f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -12,6 +12,7 @@ use Friendica\App; use Friendica\Core\Addon; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; require_once("include/items.php"); @@ -60,7 +61,7 @@ function parse_url_content(App $a) { // the URL with the corresponding BBCode media tag $redirects = 0; // Fetch the header of the URL - $result = z_fetch_url($url, false, $redirects, ["novalidate" => true, "nobody" => true]); + $result = Network::zFetchURL($url, false, $redirects, ["novalidate" => true, "nobody" => true]); if($result["success"]) { // Convert the header fields into an array $hdrs = []; diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 28c872f32c..231970820f 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -981,7 +981,7 @@ class GContact $url = $server."/main/statistics"; - $result = z_fetch_url($url); + $result = Network::zFetchURL($url); if (!$result["success"]) { return false; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 2cc855216b..94fd929e10 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -18,6 +18,7 @@ use Friendica\Model\Profile; use Friendica\Protocol\Email; use Friendica\Protocol\Feed; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -107,7 +108,7 @@ class Probe logger("Probing for ".$host, LOGGER_DEBUG); - $ret = z_fetch_url($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::zFetchURL($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['success']) { $xml = $ret['body']; $xrd = parse_xml_string($xml, false); @@ -115,7 +116,7 @@ class Probe } if (!is_object($xrd)) { - $ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { logger("Probing timeout for ".$url, LOGGER_DEBUG); return false; @@ -692,7 +693,7 @@ class Probe $xrd_timeout = Config::get('system', 'xrd_timeout', 20); $redirects = 0; - $ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -759,7 +760,7 @@ class Probe */ private static function pollNoscrape($noscrape_url, $data) { - $ret = z_fetch_url($noscrape_url); + $ret = Network::zFetchURL($noscrape_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -993,7 +994,7 @@ class Probe */ private static function pollHcard($hcard_url, $data, $dfrn = false) { - $ret = z_fetch_url($hcard_url); + $ret = Network::zFetchURL($hcard_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1232,7 +1233,7 @@ class Probe $pubkey = substr($pubkey, 5); } } elseif (normalise_link($pubkey) == 'http://') { - $ret = z_fetch_url($pubkey); + $ret = Network::zFetchURL($pubkey); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1264,7 +1265,7 @@ class Probe } // Fetch all additional data from the feed - $ret = z_fetch_url($data["poll"]); + $ret = Network::zFetchURL($data["poll"]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1448,7 +1449,7 @@ class Probe */ private static function feed($url, $probe = true) { - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 808e8aaa2a..4289769e41 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -25,6 +25,7 @@ use Friendica\Model\User; use Friendica\Object\Image; use Friendica\Protocol\OStatus; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -1186,7 +1187,7 @@ class DFRN logger('dfrn_deliver: ' . $url); - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return -2; // timed out diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 3b04a11d27..87b894a717 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -17,6 +17,7 @@ use Friendica\Model\Conversation; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Util\Lock; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; use DOMDocument; @@ -725,7 +726,7 @@ class OStatus self::$conv_list[$conversation] = true; - $conversation_data = z_fetch_url($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $conversation_data = Network::zFetchURL($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$conversation_data['success']) { return; @@ -753,7 +754,7 @@ class OStatus } } if ($file != '') { - $conversation_atom = z_fetch_url($attribute['href']); + $conversation_atom = Network::zFetchURL($attribute['href']); if ($conversation_atom['success']) { $xml = $conversation_atom['body']; @@ -869,7 +870,7 @@ class OStatus return; } - $self_data = z_fetch_url($self); + $self_data = Network::zFetchURL($self); if (!$self_data['success']) { return; @@ -914,7 +915,7 @@ class OStatus } $stored = false; - $related_data = z_fetch_url($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $related_data = Network::zFetchURL($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$related_data['success']) { return; @@ -945,7 +946,7 @@ class OStatus } } if ($atom_file != '') { - $related_atom = z_fetch_url($atom_file); + $related_atom = Network::zFetchURL($atom_file); if ($related_atom['success']) { logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG); @@ -957,7 +958,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); + $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG); @@ -968,7 +969,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = OStatus::convertHref($related_uri); - $related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); + $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG); diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 65e71d07a9..35ec7fe962 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -288,7 +288,7 @@ class PortableContact } // Fetch the host-meta to check if this really is a server - $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta"); if (!$serverret["success"]) { return ""; } @@ -367,7 +367,7 @@ class PortableContact $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url))); if ($server) { - $noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); + $noscraperet = Network::zFetchURL($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); if ($noscraperet["success"] && ($noscraperet["body"] != "")) { $noscrape = json_decode($noscraperet["body"], true); @@ -481,7 +481,7 @@ class PortableContact GContact::update($contact); - $feedret = z_fetch_url($data["poll"]); + $feedret = Network::zFetchURL($data["poll"]); if (!$feedret["success"]) { $fields = ['last_failure' => datetime_convert()]; @@ -632,7 +632,7 @@ class PortableContact */ private static function fetchNodeinfo($server_url) { - $serverret = z_fetch_url($server_url."/.well-known/nodeinfo"); + $serverret = Network::zFetchURL($server_url."/.well-known/nodeinfo"); if (!$serverret["success"]) { return false; } @@ -664,7 +664,7 @@ class PortableContact return false; } - $serverret = z_fetch_url($nodeinfo_url); + $serverret = Network::zFetchURL($nodeinfo_url); if (!$serverret["success"]) { return false; } @@ -873,7 +873,7 @@ class PortableContact $server_url = str_replace("http://", "https://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout. // But we want to make sure to only quit if we are mostly sure that this server url fits. @@ -890,7 +890,7 @@ class PortableContact $server_url = str_replace("https://", "http://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { @@ -926,7 +926,7 @@ class PortableContact // Look for poco if (!$failure) { - $serverret = z_fetch_url($server_url."/poco"); + $serverret = Network::zFetchURL($server_url."/poco"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->totalResults)) { @@ -952,7 +952,7 @@ class PortableContact if (!$failure) { // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers - $serverret = z_fetch_url($server_url); + $serverret = Network::zFetchURL($server_url); if (!$serverret["success"] || ($serverret["body"] == "")) { $failure = true; @@ -991,7 +991,7 @@ class PortableContact // Test for Statusnet // Will also return data for Friendica and GNU Social - but it will be overwritten later // The "not implemented" is a special treatment for really, really old Friendica versions - $serverret = z_fetch_url($server_url."/api/statusnet/version.json"); + $serverret = Network::zFetchURL($server_url."/api/statusnet/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "StatusNet"; @@ -1002,7 +1002,7 @@ class PortableContact } // Test for GNU Social - $serverret = z_fetch_url($server_url."/api/gnusocial/version.json"); + $serverret = Network::zFetchURL($server_url."/api/gnusocial/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "GNU Social"; @@ -1014,7 +1014,7 @@ class PortableContact // Test for Mastodon $orig_version = $version; - $serverret = z_fetch_url($server_url."/api/v1/instance"); + $serverret = Network::zFetchURL($server_url."/api/v1/instance"); if ($serverret["success"] && ($serverret["body"] != '')) { $data = json_decode($serverret["body"]); @@ -1037,7 +1037,7 @@ class PortableContact if (!$failure) { // Test for Hubzilla and Red - $serverret = z_fetch_url($server_url."/siteinfo.json"); + $serverret = Network::zFetchURL($server_url."/siteinfo.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->url)) { @@ -1065,7 +1065,7 @@ class PortableContact } } else { // Test for Hubzilla, Redmatrix or Friendica - $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); + $serverret = Network::zFetchURL($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->site->server)) { @@ -1120,7 +1120,7 @@ class PortableContact // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { - $serverret = z_fetch_url($server_url."/statistics.json"); + $serverret = Network::zFetchURL($server_url."/statistics.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); @@ -1182,10 +1182,10 @@ class PortableContact // Check for noscrape // Friendica servers could be detected as OStatus servers if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) { - $serverret = z_fetch_url($server_url."/friendica/json"); + $serverret = Network::zFetchURL($server_url."/friendica/json"); if (!$serverret["success"]) { - $serverret = z_fetch_url($server_url."/friendika/json"); + $serverret = Network::zFetchURL($server_url."/friendika/json"); } if ($serverret["success"]) { @@ -1295,7 +1295,7 @@ class PortableContact */ private static function fetchServerlist($poco) { - $serverret = z_fetch_url($poco."/@server"); + $serverret = Network::zFetchURL($poco."/@server"); if (!$serverret["success"]) { return; } @@ -1344,7 +1344,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $serverdata = z_fetch_url($api, false, $redirects, ['headers' => $header]); + $serverdata = Network::zFetchURL($api, false, $redirects, ['headers' => $header]); if ($serverdata['success']) { $servers = json_decode($serverdata['body']); foreach ($servers->instances as $server) { @@ -1361,7 +1361,7 @@ class PortableContact //if (!Config::get('system','ostatus_disabled')) { // $serverdata = "http://gstools.org/api/get_open_instances/"; - // $result = z_fetch_url($serverdata); + // $result = Network::zFetchURL($serverdata); // if ($result["success"]) { // $servers = json_decode($result["body"]); @@ -1390,7 +1390,7 @@ class PortableContact logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG); - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { $data = json_decode($retdata["body"]); @@ -1409,7 +1409,7 @@ class PortableContact $success = false; - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); $success = self::discoverServer(json_decode($retdata["body"])); @@ -1494,7 +1494,7 @@ class PortableContact // Fetch all contacts from a given user from the other server $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { self::discoverServer(json_decode($retdata["body"]), 3); } diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 8940c02055..35e812a5c9 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -38,9 +38,9 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBM; use Friendica\Model\User; +use Friendica\Util\Network; use dba; -require_once 'include/dba.php'; require_once 'include/dba.php'; class ExAuth @@ -181,7 +181,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $data = z_fetch_url($url); + $data = Network::zFetchURL($url); if (!is_array($data)) { return false; diff --git a/src/Util/Network.php b/src/Util/Network.php index 39f2e03511..ebe6abda47 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -233,7 +233,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @curl_close($ch); - return z_fetch_url($newurl, $binary, $redirects, $opts); + return self::zFetchURL($newurl, $binary, $redirects, $opts); } } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index b03fcd9827..67aebb4c72 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -8,6 +8,7 @@ namespace Friendica\Util; use Friendica\Content\OEmbed; use Friendica\Core\Addon; use Friendica\Object\Image; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -145,7 +146,7 @@ class ParseUrl $siteinfo["url"] = $url; $siteinfo["type"] = "link"; - $data = z_fetch_url($url); + $data = Network::zFetchURL($url); if (!$data['success']) { return($siteinfo); } diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index d72579cfb5..0172bcd342 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -281,7 +281,7 @@ class DiscoverPoCo { $url = "http://gstools.org/api/users_search/".urlencode($search); - $result = z_fetch_url($url); + $result = Network::zFetchURL($url); if (!$result["success"]) { return false; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 293cd265e2..98b5f77869 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -10,6 +10,7 @@ use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\Email; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -176,7 +177,7 @@ class OnePoll . '&type=data&last_update=' . $last_update . '&perm=' . $perm ; - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { // set the last-update so we don't keep polling @@ -311,7 +312,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $ret = z_fetch_url($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); + $ret = Network::zFetchURL($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { -- 2.39.5