From c67452f72e34cfa94977dd8b6f4a8fdd09e79523 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:09:48 -0500 Subject: [PATCH] Move fetch_url move fetch_url function --- include/api.php | 3 ++- include/bbcode.php | 7 ++++--- include/network.php | 2 +- mod/dfrn_poll.php | 5 +++-- mod/dfrn_request.php | 3 ++- mod/dirfind.php | 3 ++- mod/install.php | 5 +++-- mod/nodeinfo.php | 3 ++- mod/oexchange.php | 3 ++- mod/proxy.php | 3 ++- mod/pubsubhubbub.php | 3 ++- spec/dfrn2_contact_request.svg | 4 ++-- src/Content/OEmbed.php | 7 ++++--- src/Core/Worker.php | 4 ++-- src/Model/GContact.php | 3 ++- src/Model/Photo.php | 3 ++- src/Model/User.php | 3 ++- src/Object/Image.php | 3 ++- src/Protocol/Diaspora.php | 6 +++--- src/Protocol/PortableContact.php | 3 ++- src/Protocol/Salmon.php | 3 ++- src/Util/Network.php | 2 +- src/Worker/CheckVersion.php | 3 ++- src/Worker/Directory.php | 3 ++- src/Worker/DiscoverPoCo.php | 3 ++- 25 files changed, 55 insertions(+), 35 deletions(-) diff --git a/include/api.php b/include/api.php index 8579d2d185..610cd26dda 100644 --- a/include/api.php +++ b/include/api.php @@ -35,6 +35,7 @@ use Friendica\Network\HTTPException\UnauthorizedException; use Friendica\Network\HTTPException\TooManyRequestsException; use Friendica\Object\Image; use Friendica\Protocol\Diaspora; +use Friendica\Util\Network; use Friendica\Util\XML; require_once 'include/bbcode.php'; @@ -5073,7 +5074,7 @@ function api_get_nick($profile) if ($StatusnetHost != $profile) { $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { - $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { $nick = $user->screen_name; diff --git a/include/bbcode.php b/include/bbcode.php index dfaed8ef78..0544c4c616 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -13,6 +13,7 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Model\Contact; use Friendica\Util\Map; +use Friendica\Util\Network; require_once 'include/event.php'; require_once 'mod/proxy.php'; @@ -688,7 +689,7 @@ function GetProfileUsername($profile, $username, $compact = false, $getnetwork = $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { /// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here - $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { if ($getnetwork) { @@ -749,7 +750,7 @@ function bb_RemovePictureLinks($match) { // if its not a picture then look if its a page that contains a picture link require_once("include/network.php"); - $body = fetch_url($match[1]); + $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); @@ -806,7 +807,7 @@ function bb_CleanPictureLinksSub($match) { // if its not a picture then look if its a page that contains a picture link require_once("include/network.php"); - $body = fetch_url($match[1]); + $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); diff --git a/include/network.php b/include/network.php index 7798fd9cd8..f6a864a635 100644 --- a/include/network.php +++ b/include/network.php @@ -57,7 +57,7 @@ function blocked_url($url) return Network::blockedURL($url); } -function allowedEmail($email) +function allowed_email($email) { return Network::allowedEmail($email); } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index e5ca96934a..7b0785b6f3 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -11,6 +11,7 @@ use Friendica\Database\DBM; use Friendica\Module\Login; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; +use Friendica\Util\Network; require_once 'include/items.php'; @@ -98,7 +99,7 @@ function dfrn_poll_init(App $a) ); if (DBM::is_result($r)) { - $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); + $s = Network::fetchURL($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); @@ -481,7 +482,7 @@ function dfrn_poll_content(App $a) if (($type === 'profile') && (strlen($sec))) { // URL reply if ($dfrn_version < 2.2) { - $s = fetch_url($r[0]['poll'] + $s = Network::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 aada465ad2..18a6eefaf2 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -23,6 +23,7 @@ use Friendica\Model\User; use Friendica\Model\Profile; use Friendica\Module\Login; use Friendica\Network\Probe; +use Friendica\Util\Network; require_once 'include/enotify.php'; @@ -182,7 +183,7 @@ function dfrn_request_post(App $a) } if (strlen($dfrn_request) && strlen($confirm_key)) { - $s = fetch_url($dfrn_request . '?confirm_key=' . $confirm_key); + $s = Network::fetchURL($dfrn_request . '?confirm_key=' . $confirm_key); } // (ignore reply, nothing we can do it failed) diff --git a/mod/dirfind.php b/mod/dirfind.php index f1119a2979..c010aaac92 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -14,6 +14,7 @@ use Friendica\Model\GContact; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; require_once 'mod/contacts.php'; @@ -177,7 +178,7 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); if(strlen(Config::get('system','directory'))) - $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::fetchURL(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $j = json_decode($x); } diff --git a/mod/install.php b/mod/install.php index cbad3b2548..ef9f023f52 100644 --- a/mod/install.php +++ b/mod/install.php @@ -8,6 +8,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Database\DBStructure; use Friendica\Object\Image; +use Friendica\Util\Network; $install_wizard_pass = 1; @@ -482,10 +483,10 @@ function check_htaccess(&$checks) { $status = true; $help = ""; if (function_exists('curl_init')) { - $test = fetch_url(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchURL(System::baseUrl()."/install/testrewrite"); if ($test != "ok") { - $test = fetch_url(normalise_link(System::baseUrl()."/install/testrewrite")); + $test = Network::fetchURL(normalise_link(System::baseUrl()."/install/testrewrite")); } if ($test != "ok") { diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index bcaf8e7a93..d0c4acab02 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -9,6 +9,7 @@ use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\System; use Friendica\Core\Config; +use Friendica\Util\Network; function nodeinfo_wellknown(App $a) { $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0', @@ -246,7 +247,7 @@ function nodeinfo_cron() { // Now trying to register $url = 'http://the-federation.info/register/'.$a->get_hostname(); logger('registering url: '.$url, LOGGER_DEBUG); - $ret = fetch_url($url); + $ret = Network::fetchURL($url); logger('registering answer: '.$ret, LOGGER_DEBUG); logger('cron_end'); diff --git a/mod/oexchange.php b/mod/oexchange.php index 902499c031..79414a7f6a 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Module\Login; +use Friendica\Util\Network; function oexchange_init(App $a) { @@ -39,7 +40,7 @@ function oexchange_content(App $a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $s = fetch_url(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $s = Network::fetchURL(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); if (! strlen($s)) { return; diff --git a/mod/proxy.php b/mod/proxy.php index 538275ef00..1497185917 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Photo; use Friendica\Object\Image; +use Friendica\Util\Network; define('PROXY_DEFAULT_TIME', 86400); // 1 Day @@ -161,7 +162,7 @@ function proxy_init(App $a) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = fetch_url($_REQUEST['url'], true, $redirects, 10); + $img_str = Network::fetchURL($_REQUEST['url'], true, $redirects, 10); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index f3134308fb..c2091d4de8 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -3,6 +3,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Database\DBM; +use Friendica\Util\Network; function post_var($name) { return (x($_POST, $name)) ? notags(trim($_POST[$name])) : ''; @@ -109,7 +110,7 @@ function pubsubhubbub_init(App $a) { // we don't actually enforce the lease time because GNU // Social/StatusNet doesn't honour it (yet) - $body = fetch_url($hub_callback . "?" . $params); + $body = Network::fetchURL($hub_callback . "?" . $params); $ret = $a->get_curl_code(); // give up if the HTTP return code wasn't a success (2xx) diff --git a/spec/dfrn2_contact_request.svg b/spec/dfrn2_contact_request.svg index e85eaf20b5..23b040985f 100644 --- a/spec/dfrn2_contact_request.svg +++ b/spec/dfrn2_contact_request.svg @@ -93,9 +93,9 @@ text { font:12px Dialog; } - create a contact for Karen in the contact table with the scraped data with blocked = 1 and pending = 1 (Karens pubkey becomes the contact site-pubkey) -- fetch_url($dfrn_request . '?confirm_key=' . +- Network::fetchURL($dfrn_request . '?confirm_key=' . $confirm_key); -- fetch_url(http://karenhomepage.com/dfrn_request? +- Network::fetchURL(http://karenhomepage.com/dfrn_request? confirm_key=”ABC123”) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 9f1df51745..80fab8c647 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -10,6 +10,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Database\DBM; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; use dba; use DOMDocument; @@ -77,7 +78,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery $redirects = 0; - $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); + $html_text = Network::fetchURL($embedurl, false, $redirects, 15, "text/*"); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -85,13 +86,13 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); break; } } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 893b1bccc8..11146e4a21 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -10,7 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Process; use Friendica\Util\Lock; - +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -888,7 +888,7 @@ class Worker } $url = System::baseUrl()."/worker"; - fetch_url($url, false, $redirects, 1); + Network::fetchURL($url, false, $redirects, 1); } /** diff --git a/src/Model/GContact.php b/src/Model/GContact.php index d125ff8fe2..28c872f32c 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -13,6 +13,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; use dba; use Exception; @@ -568,7 +569,7 @@ class GContact $done[] = System::baseUrl() . '/poco'; if (strlen(Config::get('system', 'directory'))) { - $x = fetch_url(get_server()."/pubsites"); + $x = Network::fetchURL(get_server()."/pubsites"); if ($x) { $j = json_decode($x); if ($j->entries) { diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 94d5581bf0..23d893c925 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -12,6 +12,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Object\Image; +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -101,7 +102,7 @@ class Photo $photo_failure = false; $filename = basename($image_url); - $img_str = fetch_url($image_url, true); + $img_str = Network::fetchURL($image_url, true); if ($quit_on_error && ($img_str == "")) { return false; diff --git a/src/Model/User.php b/src/Model/User.php index 07df7ca615..ecd1040b75 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -17,6 +17,7 @@ use Friendica\Model\Group; use Friendica\Model\Photo; use Friendica\Object\Image; use Friendica\Util\Crypto; +use Friendica\Util\Network; use dba; use Exception; @@ -468,7 +469,7 @@ class User $photo_failure = false; $filename = basename($photo); - $img_str = fetch_url($photo, true); + $img_str = Network::fetchURL($photo, true); // guess mimetype from headers or filename $type = Image::guessType($photo, true); diff --git a/src/Object/Image.php b/src/Object/Image.php index 2feb3b9241..84c462205e 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -12,6 +12,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Photo; +use Friendica\Util\Network; use Exception; use Imagick; use ImagickPixel; @@ -773,7 +774,7 @@ class Image $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { - $img_str = fetch_url($url, true, $redirects, 4); + $img_str = Network::fetchURL($url, true, $redirects, 4); $filesize = strlen($img_str); if (function_exists("getimagesizefromstring")) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 540f82cc63..14bad8e1d9 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -25,8 +25,8 @@ use Friendica\Model\Queue; use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; - use dba; use SimpleXMLElement; @@ -1257,7 +1257,7 @@ class Diaspora logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $envelope = fetch_url($source_url); + $envelope = Network::fetchURL($source_url); if ($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verifyMagicEnvelope($envelope); @@ -1275,7 +1275,7 @@ class Diaspora $source_url = $server."/p/".urlencode($guid).".xml"; logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $x = fetch_url($source_url); + $x = Network::fetchURL($source_url); if (!$x) { return false; } diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 22615fee10..65e71d07a9 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -15,6 +15,7 @@ use Friendica\Database\DBM; use Friendica\Model\GContact; use Friendica\Model\Profile; use Friendica\Network\Probe; +use Friendica\Util\Network; use dba; use DOMDocument; use DOMXPath; @@ -85,7 +86,7 @@ class PortableContact logger('load: ' . $url, LOGGER_DEBUG); - $s = fetch_url($url); + $s = Network::fetchURL($url); logger('load: returns ' . $s, LOGGER_DATA); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 5b0c66fb9d..3e8d368169 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -6,6 +6,7 @@ namespace Friendica\Protocol; use Friendica\Network\Probe; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; /** @@ -50,7 +51,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (normalise_link($ret[$x]) == 'http://') { - $ret[$x] = fetch_url($ret[$x]); + $ret[$x] = Network::fetchURL($ret[$x]); } } } diff --git a/src/Util/Network.php b/src/Util/Network.php index f25d9c9a26..39f2e03511 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -714,7 +714,7 @@ class Network } else { $scaled = $mtch[1]; } - $i = fetch_url($scaled); + $i = self::fetchURL($scaled); if (! $i) { return $srctext; } diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index b7e99cb67e..2e089502f1 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -8,6 +8,7 @@ namespace Friendica\Worker; use Friendica\Core\Config; +use Friendica\Util\Network; /** * @brief check the git repository VERSION file and save the version to the DB @@ -37,7 +38,7 @@ class CheckVersion { logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG); // fetch the VERSION file - $gitversion = dbesc(trim(fetch_url($checked_url))); + $gitversion = dbesc(trim(Network::fetchURL($checked_url))); logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG); Config::set('system', 'git_friendica_version', $gitversion); diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index e38f9eeeee..634c5a5ec5 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -10,6 +10,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; +use Friendica\Util\Network; class Directory { public static function execute($url = '') { @@ -32,7 +33,7 @@ class Directory { logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); if (strlen($arr['url'])) { - fetch_url($dir . '?url=' . bin2hex($arr['url'])); + Network::fetchURL($dir . '?url=' . bin2hex($arr['url'])); } return; diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index c00db89ff5..d72579cfb5 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -11,6 +11,7 @@ use Friendica\Database\DBM; use Friendica\Model\GContact; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; require_once 'include/datetime.php'; @@ -217,7 +218,7 @@ class DiscoverPoCo { } } - $x = fetch_url(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); + $x = Network::fetchURL(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $j = json_decode($x); if (count($j->results)) {