From fe940a7cfbfcb640cc1f7f39e855f675aa90b92c Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 4 Mar 2020 22:07:04 +0100 Subject: [PATCH] Move post/curl/fetchUrl/fetchUrlFull to own class "Network\HTTPRequest" --- blogger/blogger.php | 3 ++- curweather/curweather.php | 3 ++- discourse/discourse.php | 5 +++-- dwpost/dwpost.php | 3 ++- geocoordinates/geocoordinates.php | 3 ++- geonames/geonames.php | 3 ++- ijpost/ijpost.php | 3 ++- jappixmini/jappixmini.php | 3 ++- leistungsschutzrecht/leistungsschutzrecht.php | 3 ++- libertree/libertree.php | 3 ++- ljpost/ljpost.php | 3 ++- mailstream/mailstream.php | 3 ++- mastodoncustomemojis/mastodoncustomemojis.php | 3 ++- openstreetmap/openstreetmap.php | 3 ++- pumpio/pumpio.php | 3 ++- statusnet/statusnet.php | 11 ++++++----- twitter/twitter.php | 5 +++-- wppost/wppost.php | 3 ++- 18 files changed, 42 insertions(+), 24 deletions(-) diff --git a/blogger/blogger.php b/blogger/blogger.php index e0b5f535..4ffd5069 100644 --- a/blogger/blogger.php +++ b/blogger/blogger.php @@ -11,6 +11,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\XML; @@ -225,7 +226,7 @@ EOT; Logger::log('blogger: data: ' . $xml, Logger::DATA); if ($bl_blog !== 'test') { - $x = Network::post($bl_blog, $xml)->getBody(); + $x = HTTPRequest::post($bl_blog, $xml)->getBody(); } Logger::log('posted to blogger: ' . (($x) ? $x : ''), Logger::DEBUG); diff --git a/curweather/curweather.php b/curweather/curweather.php index e4b6119f..533555b8 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -15,6 +15,7 @@ use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; @@ -49,7 +50,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti } try { - $res = new SimpleXMLElement(Network::fetchUrl($url)); + $res = new SimpleXMLElement(HTTPRequest::fetchUrl($url)); } catch (Exception $e) { if (empty($_SESSION['curweather_notice_shown'])) { info(DI::l10n()->t('Error fetching weather data. Error was: '.$e->getMessage())); diff --git a/discourse/discourse.php b/discourse/discourse.php index f684425a..8d6b6624 100644 --- a/discourse/discourse.php +++ b/discourse/discourse.php @@ -16,6 +16,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Content\Text\Markdown; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\Strings; Use Friendica\Util\DateTimeFormat; @@ -114,7 +115,7 @@ function discourse_email_getmessage(App $a, &$message) function discourse_fetch_post($host, $topic, $pid) { $url = $host . '/t/' . $topic . '/' . $pid . '.json'; - $curlResult = Network::curl($url); + $curlResult = HTTPRequest::curl($url); if (!$curlResult->isSuccess()) { Logger::info('No success', ['url' => $url]); return false; @@ -151,7 +152,7 @@ function discourse_fetch_post_from_api(&$message, $post, $host) { $hostaddr = 'https://' . $host; $url = $hostaddr . '/posts/' . $post . '.json'; - $curlResult = Network::curl($url); + $curlResult = HTTPRequest::curl($url); if (!$curlResult->isSuccess()) { return false; } diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 9bcee9c2..503ec215 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -14,6 +14,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; @@ -230,7 +231,7 @@ EOT; Logger::log('dwpost: data: ' . $xml, Logger::DATA); if ($dw_blog !== 'test') { - $x = Network::post($dw_blog, $xml, ["Content-Type: text/xml"])->getBody(); + $x = HTTPRequest::post($dw_blog, $xml, ["Content-Type: text/xml"])->getBody(); } Logger::log('posted to dreamwidth: ' . ($x) ? $x : '', Logger::DEBUG); diff --git a/geocoordinates/geocoordinates.php b/geocoordinates/geocoordinates.php index 7a7a6d9a..38afb953 100644 --- a/geocoordinates/geocoordinates.php +++ b/geocoordinates/geocoordinates.php @@ -9,6 +9,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\Strings; @@ -52,7 +53,7 @@ function geocoordinates_resolve_item(&$item) return; } - $s = Network::fetchUrl("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language); + $s = HTTPRequest::fetchUrl("https://api.opencagedata.com/geocode/v1/json?q=" . $coords[0] . "," . $coords[1] . "&key=" . $key . "&language=" . $language); if (!$s) { Logger::log("API could not be queried", Logger::DEBUG); diff --git a/geonames/geonames.php b/geonames/geonames.php index 38888ecb..21cb79ac 100644 --- a/geonames/geonames.php +++ b/geonames/geonames.php @@ -11,6 +11,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\ConfigFileLoader; use Friendica\Util\Network; use Friendica\Util\XML; @@ -78,7 +79,7 @@ function geonames_post_hook(App $a, array &$item) /* OK, we're allowed to do our stuff. */ - $s = Network::fetchUrl('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); + $s = HTTPRequest::fetchUrl('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); if (!$s) { return; diff --git a/ijpost/ijpost.php b/ijpost/ijpost.php index 71a4c718..04c6a20e 100644 --- a/ijpost/ijpost.php +++ b/ijpost/ijpost.php @@ -12,6 +12,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; @@ -228,7 +229,7 @@ EOT; Logger::log('ijpost: data: ' . $xml, Logger::DATA); if ($ij_blog !== 'test') { - $x = Network::post($ij_blog, $xml, ["Content-Type: text/xml"])->getBody(); + $x = HTTPRequest::post($ij_blog, $xml, ["Content-Type: text/xml"])->getBody(); } Logger::log('posted to insanejournal: ' . $x ? $x : '', Logger::DEBUG); } diff --git a/jappixmini/jappixmini.php b/jappixmini/jappixmini.php index ad4d4901..b43e1a07 100644 --- a/jappixmini/jappixmini.php +++ b/jappixmini/jappixmini.php @@ -69,6 +69,7 @@ use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\User; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; function jappixmini_install() @@ -660,7 +661,7 @@ function jappixmini_cron(App $a, $d) try { // send request - $answer_json = Network::fetchUrl($url); + $answer_json = HTTPRequest::fetchUrl($url); // parse answer $answer = json_decode($answer_json); diff --git a/leistungsschutzrecht/leistungsschutzrecht.php b/leistungsschutzrecht/leistungsschutzrecht.php index 8bb6f526..b2bebc53 100644 --- a/leistungsschutzrecht/leistungsschutzrecht.php +++ b/leistungsschutzrecht/leistungsschutzrecht.php @@ -8,6 +8,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; function leistungsschutzrecht_install() { @@ -79,7 +80,7 @@ function leistungsschutzrecht_fetchsites() { // This list works - but question is how current it is $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt"; - $sitelist = Network::fetchUrl($url); + $sitelist = HTTPRequest::fetchUrl($url); $siteurls = explode(',', $sitelist); $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de']; diff --git a/libertree/libertree.php b/libertree/libertree.php index 7dfd8a36..418562c3 100644 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -12,6 +12,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; function libertree_install() @@ -255,7 +256,7 @@ function libertree_send(&$a,&$b) { // 'token' => $ltree_api_token ]; - $result = Network::post($ltree_blog, $params)->getBody(); + $result = HTTPRequest::post($ltree_blog, $params)->getBody(); Logger::log('libertree: ' . $result); } } diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php index 382832c5..422eb535 100644 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -12,6 +12,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; @@ -240,7 +241,7 @@ EOT; Logger::log('ljpost: data: ' . $xml, Logger::DATA); if ($lj_blog !== 'test') { - $x = Network::post($lj_blog, $xml, ["Content-Type: text/xml"])->getBody(); + $x = HTTPRequest::post($lj_blog, $xml, ["Content-Type: text/xml"])->getBody(); } Logger::log('posted to livejournal: ' . ($x) ? $x : '', Logger::DEBUG); } diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 89e6cc01..c24bb8bf 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -12,6 +12,7 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Protocol\Activity; use Friendica\Util\Network; use Friendica\Model\Item; @@ -169,7 +170,7 @@ function mailstream_do_images($a, &$item, &$attachments) { continue; } $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-'); - $curlResult = Network::fetchUrlFull($url, true, 0, '', $cookiejar); + $curlResult = HTTPRequest::fetchUrlFull($url, true, 0, '', $cookiejar); $attachments[$url] = [ 'data' => $curlResult->getBody(), 'guid' => hash("crc32", $url), diff --git a/mastodoncustomemojis/mastodoncustomemojis.php b/mastodoncustomemojis/mastodoncustomemojis.php index a6c95d34..9dd27048 100644 --- a/mastodoncustomemojis/mastodoncustomemojis.php +++ b/mastodoncustomemojis/mastodoncustomemojis.php @@ -15,6 +15,7 @@ use Friendica\Core\Cache\Duration; use Friendica\Core\Hook; use Friendica\Core\Protocol; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; @@ -90,7 +91,7 @@ function mastodoncustomemojis_fetch_custom_emojis_for_url($api_base_url) $api_url = $api_base_url . '/api/v1/custom_emojis'; - $fetchResult = Network::fetchUrlFull($api_url); + $fetchResult = HTTPRequest::fetchUrlFull($api_url); if ($fetchResult->isSuccess()) { $emojis_array = json_decode($fetchResult->getBody(), true); diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index 5df1c7d7..7cddb24e 100644 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -14,6 +14,7 @@ use Friendica\Core\Cache\Duration; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; +use Friendica\Network\HTTPRequest; use Friendica\Util\ConfigFileLoader; use Friendica\Util\Network; use Friendica\Util\Strings; @@ -132,7 +133,7 @@ function openstreetmap_get_coordinates($a, &$b) $j = DI::cache()->get($cachekey); if (is_null($j)) { - $curlResult = Network::curl($nomserver . $args); + $curlResult = HTTPRequest::curl($nomserver . $args); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); DI::cache()->set($cachekey, $j, Duration::MONTH); diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index c6c492d4..4fe1390f 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -19,6 +19,7 @@ use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\User; +use Friendica\Network\HTTPRequest; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ConfigFileLoader; @@ -1610,7 +1611,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return Network::curl($url, false, ['timeout' => 10])->isSuccess(); + return HTTPRequest::curl($url, false, ['timeout' => 10])->isSuccess(); } /* diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 0ed0f55c..718f1d6d 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -54,6 +54,7 @@ use Friendica\Model\Item; use Friendica\Model\ItemContent; use Friendica\Model\Photo; use Friendica\Model\User; +use Friendica\Network\HTTPRequest; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -154,7 +155,7 @@ function statusnet_settings_post(App $a, $post) foreach ($globalsn as $asn) { if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) { $apibase = $asn['apiurl']; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = HTTPRequest::fetchUrl($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']); DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']); @@ -172,7 +173,7 @@ function statusnet_settings_post(App $a, $post) // we'll check the API Version for that, if we don't get one we'll try to fix the path but will // resign quickly after this one try to fix the path ;-) $apibase = $_POST['statusnet-baseapi']; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = HTTPRequest::fetchUrl($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { // ok the API path is correct, let's save the settings DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); @@ -182,7 +183,7 @@ function statusnet_settings_post(App $a, $post) } else { // the API path is not correct, maybe missing trailing / ? $apibase = $apibase . '/'; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = HTTPRequest::fetchUrl($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { // ok the API path is now correct, let's save the settings DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); @@ -612,7 +613,7 @@ function statusnet_post_hook(App $a, &$b) } if ($image != "") { - $img_str = Network::fetchUrl($image); + $img_str = HTTPRequest::fetchUrl($image); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); $postdata = ["status" => $msg, "media[]" => $tempfile]; @@ -1475,7 +1476,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } elseif ($oembed_data->type != "link") { $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); } else { - $img_str = Network::fetchUrl($expanded_url, true, 4); + $img_str = HTTPRequest::fetchUrl($expanded_url, true, 4); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); diff --git a/twitter/twitter.php b/twitter/twitter.php index 673b3b75..34851018 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -82,6 +82,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\ItemContent; use Friendica\Model\User; +use Friendica\Network\HTTPRequest; use Friendica\Protocol\Activity; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; @@ -655,7 +656,7 @@ function twitter_post_hook(App $a, array &$b) continue; } - $img_str = Network::fetchUrl($image['url']); + $img_str = HTTPRequest::fetchUrl($image['url']); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); @@ -1201,7 +1202,7 @@ function twitter_expand_entities(App $a, $body, $item, $picture) } elseif ($oembed_data->type != 'link') { $body = str_replace($url->url, '[url=' . $expanded_url . ']' . $url->display_url . '[/url]', $body); } else { - $img_str = Network::fetchUrl($final_url, true, 4); + $img_str = HTTPRequest::fetchUrl($final_url, true, 4); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/wppost/wppost.php b/wppost/wppost.php index 052b4074..8b1e198f 100644 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -12,6 +12,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Network\HTTPRequest; use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\XML; @@ -338,7 +339,7 @@ EOT; Logger::log('wppost: data: ' . $xml, Logger::DATA); if ($wp_blog !== 'test') { - $x = Network::post($wp_blog, $xml)->getBody(); + $x = HTTPRequest::post($wp_blog, $xml)->getBody(); } Logger::log('posted to wordpress: ' . (($x) ? $x : ''), Logger::DEBUG); }