From e3980a6d87e0ca7eff824821340152a0ed50a688 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 25 Aug 2021 21:18:05 +0200 Subject: [PATCH 1/3] Use HTTPRequestOptions constants for HTTPClient::get() --- pumpio/pumpio.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index a74aa4fa0..d93aa16db 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -20,6 +20,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPRequestOptions; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ConfigFileLoader; @@ -1593,7 +1594,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return DI::httpRequest()->get($url, ['timeout' => 10])->isSuccess(); + return DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => 10])->isSuccess(); } /* From 9c266e59cfa7939af7120506f9833448ca1615e3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 25 Aug 2021 21:45:15 +0200 Subject: [PATCH 2/3] Rename HTTPRequestOptions to HTTPClientOptions --- pumpio/pumpio.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index d93aa16db..bf6bfda36 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -20,7 +20,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; -use Friendica\Network\HTTPRequestOptions; +use Friendica\Network\HTTPClientOptions; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ConfigFileLoader; @@ -1594,7 +1594,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => 10])->isSuccess(); + return DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => 10])->isSuccess(); } /* From adada10eb624860a165b0575174a615fefa0f5ed Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 25 Aug 2021 21:54:54 +0200 Subject: [PATCH 3/3] Rename DI::httpRequest() into DI::httpClient() --- blogger/blogger.php | 2 +- curweather/curweather.php | 2 +- discourse/discourse.php | 4 ++-- dwpost/dwpost.php | 2 +- geocoordinates/geocoordinates.php | 2 +- geonames/geonames.php | 2 +- ijpost/ijpost.php | 2 +- jappixmini/jappixmini.php | 2 +- leistungsschutzrecht/leistungsschutzrecht.php | 2 +- libertree/libertree.php | 2 +- ljpost/ljpost.php | 2 +- mailstream/mailstream.php | 2 +- mastodoncustomemojis/mastodoncustomemojis.php | 2 +- nominatim/nominatim.php | 2 +- openstreetmap/openstreetmap.php | 2 +- pumpio/pumpio.php | 2 +- statusnet/statusnet.php | 12 ++++++------ twitter/twitter.php | 2 +- wppost/wppost.php | 2 +- 19 files changed, 25 insertions(+), 25 deletions(-) diff --git a/blogger/blogger.php b/blogger/blogger.php index 38470f187..37cdba091 100644 --- a/blogger/blogger.php +++ b/blogger/blogger.php @@ -208,7 +208,7 @@ EOT; Logger::log('blogger: data: ' . $xml, Logger::DATA); if ($bl_blog !== 'test') { - $x = DI::httpRequest()->post($bl_blog, $xml)->getBody(); + $x = DI::httpClient()->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 2b8682d15..303fbbf94 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -41,7 +41,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti } try { - $res = new SimpleXMLElement(DI::httpRequest()->fetch($url)); + $res = new SimpleXMLElement(DI::httpClient()->fetch($url)); } catch (Exception $e) { if (empty($_SESSION['curweather_notice_shown'])) { notice(DI::l10n()->t('Error fetching weather data. Error was: ' . $e->getMessage())); diff --git a/discourse/discourse.php b/discourse/discourse.php index f52edb9fb..35ec9be52 100644 --- a/discourse/discourse.php +++ b/discourse/discourse.php @@ -114,7 +114,7 @@ function discourse_email_getmessage(App $a, &$message) function discourse_fetch_post($host, $topic, $pid) { $url = $host . '/t/' . $topic . '/' . $pid . '.json'; - $curlResult = DI::httpRequest()->get($url); + $curlResult = DI::httpClient()->get($url); if (!$curlResult->isSuccess()) { Logger::info('No success', ['url' => $url]); return false; @@ -151,7 +151,7 @@ function discourse_fetch_post_from_api(&$message, $post, $host) { $hostaddr = 'https://' . $host; $url = $hostaddr . '/posts/' . $post . '.json'; - $curlResult = DI::httpRequest()->get($url); + $curlResult = DI::httpClient()->get($url); if (!$curlResult->isSuccess()) { return false; } diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 72e600ee6..446f41d1e 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -224,7 +224,7 @@ EOT; Logger::log('dwpost: data: ' . $xml, Logger::DATA); if ($dw_blog !== 'test') { - $x = DI::httpRequest()->post($dw_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->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 937e2f8c1..e892c2581 100644 --- a/geocoordinates/geocoordinates.php +++ b/geocoordinates/geocoordinates.php @@ -45,7 +45,7 @@ function geocoordinates_resolve_item(&$item) return; } - $s = DI::httpRequest()->fetch("https://api.opencagedata.com/geocode/v1/json?q=" . $coords[0] . "," . $coords[1] . "&key=" . $key . "&language=" . $language); + $s = DI::httpClient()->fetch("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 cf5425889..052c416fc 100644 --- a/geonames/geonames.php +++ b/geonames/geonames.php @@ -77,7 +77,7 @@ function geonames_post_hook(App $a, array &$item) /* OK, we're allowed to do our stuff. */ - $s = DI::httpRequest()->fetch('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); + $s = DI::httpClient()->fetch('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 cbd7e9b0d..b9b4e2f86 100644 --- a/ijpost/ijpost.php +++ b/ijpost/ijpost.php @@ -219,7 +219,7 @@ EOT; Logger::log('ijpost: data: ' . $xml, Logger::DATA); if ($ij_blog !== 'test') { - $x = DI::httpRequest()->post($ij_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->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 0e0abfc89..f1cfed779 100644 --- a/jappixmini/jappixmini.php +++ b/jappixmini/jappixmini.php @@ -644,7 +644,7 @@ function jappixmini_cron(App $a, $d) try { // send request - $answer_json = DI::httpRequest()->fetch($url); + $answer_json = DI::httpClient()->fetch($url); // parse answer $answer = json_decode($answer_json); diff --git a/leistungsschutzrecht/leistungsschutzrecht.php b/leistungsschutzrecht/leistungsschutzrecht.php index 04bbd4741..8d00f1dd2 100644 --- a/leistungsschutzrecht/leistungsschutzrecht.php +++ b/leistungsschutzrecht/leistungsschutzrecht.php @@ -72,7 +72,7 @@ function leistungsschutzrecht_fetchsites() { // This list works - but question is how current it is $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt"; - $sitelist = DI::httpRequest()->fetch($url); + $sitelist = DI::httpClient()->fetch($url); $siteurls = explode(',', $sitelist); $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de']; diff --git a/libertree/libertree.php b/libertree/libertree.php index a38a85824..969b4b401 100644 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -235,7 +235,7 @@ function libertree_send(&$a,&$b) { // 'token' => $ltree_api_token ]; - $result = DI::httpRequest()->post($ltree_blog, $params)->getBody(); + $result = DI::httpClient()->post($ltree_blog, $params)->getBody(); Logger::log('libertree: ' . $result); } } diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php index 896099d81..817eb59e0 100644 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -234,7 +234,7 @@ EOT; Logger::log('ljpost: data: ' . $xml, Logger::DATA); if ($lj_blog !== 'test') { - $x = DI::httpRequest()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->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 a9fbc2b41..0e5abcd48 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -204,7 +204,7 @@ function mailstream_do_images(&$item, &$attachments) continue; } $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-'); - $curlResult = DI::httpRequest()->fetchFull($url, 0, '', $cookiejar); + $curlResult = DI::httpClient()->fetchFull($url, 0, '', $cookiejar); $attachments[$url] = [ 'data' => $curlResult->getBody(), 'guid' => hash("crc32", $url), diff --git a/mastodoncustomemojis/mastodoncustomemojis.php b/mastodoncustomemojis/mastodoncustomemojis.php index eeada8625..b6b1cfd3c 100644 --- a/mastodoncustomemojis/mastodoncustomemojis.php +++ b/mastodoncustomemojis/mastodoncustomemojis.php @@ -79,7 +79,7 @@ function mastodoncustomemojis_fetch_custom_emojis_for_url($api_base_url) $api_url = $api_base_url . '/api/v1/custom_emojis'; - $fetchResult = DI::httpRequest()->fetchFull($api_url); + $fetchResult = DI::httpClient()->fetchFull($api_url); if ($fetchResult->isSuccess()) { $emojis_array = json_decode($fetchResult->getBody(), true); diff --git a/nominatim/nominatim.php b/nominatim/nominatim.php index 45f5042be..70d3e5088 100644 --- a/nominatim/nominatim.php +++ b/nominatim/nominatim.php @@ -43,7 +43,7 @@ function nominatim_resolve_item(&$item) return; } - $s = DI::httpRequest()->fetch('https://nominatim.openstreetmap.org/reverse?lat=' . $coords[0] . '&lon=' . $coords[1] . '&format=json&addressdetails=0&accept-language=' . $language); + $s = DI::httpClient()->fetch('https://nominatim.openstreetmap.org/reverse?lat=' . $coords[0] . '&lon=' . $coords[1] . '&format=json&addressdetails=0&accept-language=' . $language); if (empty($s)) { Logger::info('API could not be queried'); return; diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index 08111a0c8..d1217597e 100644 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -119,7 +119,7 @@ function openstreetmap_get_coordinates($a, &$b) $j = DI::cache()->get($cachekey); if (is_null($j)) { - $curlResult = DI::httpRequest()->get($nomserver . $args); + $curlResult = DI::httpClient()->get($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 bf6bfda36..f76e40fe4 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -1594,7 +1594,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => 10])->isSuccess(); + return DI::httpClient()->get($url, [HTTPClientOptions::TIMEOUT => 10])->isSuccess(); } /* diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 1a3ba1f97..6c7aec92f 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -136,7 +136,7 @@ function statusnet_settings_post(App $a, $post) foreach ($globalsn as $asn) { if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) { $apibase = $asn['apiurl']; - $c = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); + $c = DI::httpClient()->fetch($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']); @@ -154,7 +154,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 = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); + $c = DI::httpClient()->fetch($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']); @@ -164,7 +164,7 @@ function statusnet_settings_post(App $a, $post) } else { // the API path is not correct, maybe missing trailing / ? $apibase = $apibase . '/'; - $c = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); + $c = DI::httpClient()->fetch($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']); @@ -597,7 +597,7 @@ function statusnet_post_hook(App $a, &$b) } if ($image != "") { - $img_str = DI::httpRequest()->fetch($image); + $img_str = DI::httpClient()->fetch($image); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); $postdata = ["status" => $msg, "media[]" => $tempfile]; @@ -1426,7 +1426,7 @@ function statusnet_convertmsg(App $a, $body) Logger::log("statusnet_convertmsg: expanding url " . $match[1], Logger::DEBUG); - $expanded_url = DI::httpRequest()->finalUrl($match[1]); + $expanded_url = DI::httpClient()->finalUrl($match[1]); Logger::log("statusnet_convertmsg: fetching data for " . $expanded_url, Logger::DEBUG); @@ -1450,7 +1450,7 @@ function statusnet_convertmsg(App $a, $body) } elseif ($oembed_data->type != "link") { $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); } else { - $img_str = DI::httpRequest()->fetch($expanded_url, 4); + $img_str = DI::httpClient()->fetch($expanded_url, 4); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); diff --git a/twitter/twitter.php b/twitter/twitter.php index 0cf5637e3..fe196e3ee 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -702,7 +702,7 @@ function twitter_post_hook(App $a, array &$b) continue; } - $img_str = DI::httpRequest()->fetch($image['url']); + $img_str = DI::httpClient()->fetch($image['url']); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/wppost/wppost.php b/wppost/wppost.php index 637394d84..825593ae2 100644 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -325,7 +325,7 @@ EOT; Logger::log('wppost: data: ' . $xml, Logger::DATA); if ($wp_blog !== 'test') { - $x = DI::httpRequest()->post($wp_blog, $xml)->getBody(); + $x = DI::httpClient()->post($wp_blog, $xml)->getBody(); } Logger::log('posted to wordpress: ' . (($x) ? $x : ''), Logger::DEBUG); }