Merge remote-tracking branch 'upstream/develop' into channel-relay

This commit is contained in:
Michael 2024-01-15 06:14:55 +00:00
commit 7a13d8b8ac
63 changed files with 621 additions and 512 deletions

View file

@ -58,7 +58,7 @@ class User extends \Asika\SimpleConsole\Console
console user - Modify user settings per console commands.
Usage
bin/console user password <nickname> [<password>] [-h|--help|-?] [-v]
bin/console user add [<name> [<nickname> [<email> [<language>]]]] [-h|--help|-?] [-v]
bin/console user add [<name> [<nickname> [<email> [<language> [<avatar_url>]]]]] [-h|--help|-?] [-v]
bin/console user delete [<nickname>] [-y] [-h|--help|-?] [-v]
bin/console user allow [<nickname>] [-h|--help|-?] [-v]
bin/console user deny [<nickname>] [-h|--help|-?] [-v]
@ -228,10 +228,11 @@ HELP;
*/
private function addUser()
{
$name = $this->getArgument(1);
$nick = $this->getArgument(2);
$email = $this->getArgument(3);
$lang = $this->getArgument(4);
$name = $this->getArgument(1);
$nick = $this->getArgument(2);
$email = $this->getArgument(3);
$lang = $this->getArgument(4);
$avatar = $this->getArgument(5);
if (empty($name)) {
$this->out($this->l10n->t('Enter user name: '));
@ -262,10 +263,15 @@ HELP;
$lang = CliPrompt::prompt();
}
if (empty($avatar)) {
$this->out($this->l10n->t('Enter URL of an image to use as avatar (optional): '));
$avatar = CliPrompt::prompt();
}
if (empty($lang)) {
return UserModel::createMinimal($name, $email, $nick);
} else {
return UserModel::createMinimal($name, $email, $nick, $lang);
return UserModel::createMinimal($name, $email, $nick, $lang, $avatar);
}
}

View file

@ -80,7 +80,7 @@ class Avatar
return $fields;
}
$img_str = $fetchResult->getBody();
$img_str = $fetchResult->getBodyString();
if (empty($img_str)) {
Logger::debug('Avatar is invalid', ['avatar' => $avatar]);
return $fields;

View file

@ -383,7 +383,7 @@ class Item
'url' => $item['author-link'],
'alias' => $item['author-alias'],
];
$profile_link = Contact::magicLinkByContact($author, $item['author-link']);
$profile_link = Contact::magicLinkByContact($author, Contact::getProfileLink($author));
if (strpos($profile_link, 'contact/redir/') === 0) {
$status_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/status']);
$photos_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/photos']);

View file

@ -120,7 +120,7 @@ class OEmbed
['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
$result = DI::httpClient()->fetchFull($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth'));
if ($result->getReturnCode() === 200) {
$json_string = $result->getBody();
$json_string = $result->getBodyString();
break;
}
}

View file

@ -45,19 +45,21 @@ class Hovercard
$actions = [];
}
$contact_url = Contact::getProfileLink($contact);
// Move the contact data to the profile array so we can deliver it to
$tpl = Renderer::getMarkupTemplate('hovercard.tpl');
return Renderer::replaceMacros($tpl, [
'$profile' => [
'name' => $contact['name'],
'nick' => $contact['nick'],
'addr' => $contact['addr'] ?: $contact['url'],
'addr' => $contact['addr'] ?: $contact_url,
'thumb' => Contact::getThumb($contact),
'url' => Contact::magicLinkByContact($contact),
'nurl' => $contact['nurl'],
'location' => $contact['location'],
'about' => $contact['about'],
'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
'network_link' => Strings::formatNetworkName($contact['network'], $contact_url),
'tags' => $contact['keywords'],
'bd' => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
'account_type' => Contact::getAccountType($contact['contact-type']),

View file

@ -50,11 +50,7 @@ class VCard
Logger::warning('Incomplete contact', ['contact' => $contact ?? []]);
}
if (!Network::isValidHttpUrl($contact['url']) && Network::isValidHttpUrl($contact['alias'])) {
$contact_url = $contact['alias'];
} else {
$contact_url = $contact['url'];
}
$contact_url = Contact::getProfileLink($contact);
if ($contact['network'] != '') {
$network_link = Strings::formatNetworkName($contact['network'], $contact_url);

View file

@ -263,7 +263,7 @@ class ErrorHandler
public function handleError(int $code, string $message, string $file = '', int $line = 0, ?array $context = []): bool
{
if ($this->handleOnlyReportedErrors && !(error_reporting() & $code)) {
return false;
return true;
}
// fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries

View file

@ -234,7 +234,7 @@ class Search
$p = $page > 1 ? 'p=' . $page : '';
$curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON);
if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBody(), true);
$searchResult = json_decode($curlResult->getBodyString(), true);
if (!empty($searchResult['profiles'])) {
// Converting Directory Search results into contact-looking records
$return = array_map(function ($result) {

View file

@ -70,12 +70,12 @@ class ExternalResource implements ICanReadFromStorage
}
if (!empty($fetchResult) && $fetchResult->isSuccess()) {
$this->logger->debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
return $fetchResult->getBody();
return $fetchResult->getBodyString();
} else {
if (empty($fetchResult)) {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference));
} else {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBodyString()));
}
}
}

View file

@ -230,7 +230,7 @@ class System
* @param int $offset How many calls to shave off the top of the stack, for example if
* this is called from a centralized method that isn't relevant to the callstack
* @param bool $full If enabled, the callstack is not compacted
* @param array $exclude
* @param array $exclude
* @return string
*/
public static function callstack(int $depth = 4, int $offset = 0, bool $full = false, array $exclude = []): string

View file

@ -198,11 +198,11 @@ class APContact
try {
$curlResult = HTTPSignature::fetchRaw($url);
$failed = empty($curlResult) || empty($curlResult->getBody()) ||
$failed = empty($curlResult) || empty($curlResult->getBodyString()) ||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
if (!$failed) {
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
$failed = empty($data) || !is_array($data);
}

View file

@ -2305,7 +2305,7 @@ class Contact
try {
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
$img_str = $fetchResult->getBody();
$img_str = $fetchResult->getBodyString();
if (!empty($img_str)) {
$image = new Image($img_str, Images::getMimeTypeByData($img_str));
if ($image->isValid()) {
@ -3495,6 +3495,21 @@ class Contact
return array_column($contacts, 'id');
}
/**
* Return the link to the profile
*
* @param array $contact
* @return string
*/
public static function getProfileLink(array $contact): string
{
if (!empty($contact['alias']) && Network::isValidHttpUrl($contact['alias']) && (($contact['network'] ?? '') != Protocol::DFRN)) {
return $contact['alias'];
} else {
return $contact['url'];
}
}
/**
* Returns a magic link to authenticate remote visitors
*
@ -3553,7 +3568,7 @@ class Contact
*/
public static function magicLinkByContact(array $contact, string $url = ''): string
{
$destination = $url ?: (!Network::isValidHttpUrl($contact['url']) && !empty($contact['alias']) && Network::isValidHttpUrl($contact['alias']) ? $contact['alias'] : $contact['url']);
$destination = $url ?: self::getProfileLink($contact);
if (!DI::userSession()->isAuthenticated()) {
return $destination;

View file

@ -649,7 +649,7 @@ class GServer
}
if ($curlResult->isSuccess()) {
$json = json_decode($curlResult->getBody(), true);
$json = json_decode($curlResult->getBodyString(), true);
if (!empty($json) && is_array($json)) {
$data = self::fetchDataFromSystemActor($json, $serverdata);
$serverdata = $data['server'];
@ -657,7 +657,7 @@ class GServer
if (!$html_fetched && !in_array($serverdata['detection-method'], [self::DETECT_SYSTEM_ACTOR, self::DETECT_AP_COLLECTION])) {
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML);
}
} elseif (!$html_fetched && (strlen($curlResult->getBody()) < 1000)) {
} elseif (!$html_fetched && (strlen($curlResult->getBodyString()) < 1000)) {
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML);
}
@ -667,7 +667,7 @@ class GServer
}
}
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
self::setFailureByUrl($url);
return false;
}
@ -677,7 +677,7 @@ class GServer
$serverdata['network'] = Protocol::ACTIVITYPUB;
$serverdata['platform'] = 'threads';
}
if (($serverdata['network'] == Protocol::PHANTOM) || in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
$serverdata = self::detectMastodonAlikes($url, $serverdata);
}
@ -872,7 +872,7 @@ class GServer
return;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (!is_array($data)) {
return;
}
@ -967,7 +967,7 @@ class GServer
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1059,7 +1059,7 @@ class GServer
return [];
}
$nodeinfo = json_decode($httpResult->getBody(), true);
$nodeinfo = json_decode($httpResult->getBodyString(), true);
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
return [];
@ -1114,7 +1114,7 @@ class GServer
return [];
}
$nodeinfo = json_decode($curlResult->getBody(), true);
$nodeinfo = json_decode($curlResult->getBodyString(), true);
if (!is_array($nodeinfo)) {
return [];
@ -1214,7 +1214,7 @@ class GServer
return [];
}
$nodeinfo = json_decode($curlResult->getBody(), true);
$nodeinfo = json_decode($curlResult->getBodyString(), true);
if (!is_array($nodeinfo)) {
return [];
}
@ -1331,7 +1331,7 @@ class GServer
return [];
}
$nodeinfo = json_decode($httpResult->getBody(), true);
$nodeinfo = json_decode($httpResult->getBodyString(), true);
if (!is_array($nodeinfo)) {
return [];
@ -1434,7 +1434,7 @@ class GServer
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1587,11 +1587,11 @@ class GServer
{
$name = 'nomad';
$curlResult = DI::httpClient()->get($url . '/manifest', 'application/manifest+json');
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $name;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $name;
}
@ -1608,11 +1608,11 @@ class GServer
private static function getNomadVersion(string $url): string
{
$curlResult = DI::httpClient()->get($url . '/api/z/1.0/version', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return '';
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return '';
}
@ -1634,7 +1634,7 @@ class GServer
return false;
}
$xrd = XML::parseString($curlResult->getBody(), true);
$xrd = XML::parseString($curlResult->getBodyString(), true);
if (!is_object($xrd)) {
return false;
}
@ -1733,7 +1733,7 @@ class GServer
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1763,7 +1763,7 @@ class GServer
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1786,11 +1786,11 @@ class GServer
private static function detectPeertube(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url . '/api/v1/config', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1834,11 +1834,11 @@ class GServer
private static function detectNextcloud(string $url, array $serverdata, bool $validHostMeta): array
{
$curlResult = DI::httpClient()->get($url . '/status.php', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1870,11 +1870,11 @@ class GServer
private static function fetchWeeklyUsage(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1910,11 +1910,11 @@ class GServer
private static function detectMastodonAlikes(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url . '/api/v1/instance', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data)) {
return $serverdata;
}
@ -1982,11 +1982,11 @@ class GServer
private static function detectHubzilla(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data) || empty($data['site'])) {
return $serverdata;
}
@ -2079,11 +2079,11 @@ class GServer
{
// Test for GNU Social
$curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json', HttpClientAccept::JSON);
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') &&
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) {
$serverdata['platform'] = 'gnusocial';
// Remove junk that some GNU Social servers return
$serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBody());
$serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBodyString());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"');
$serverdata['network'] = Protocol::OSTATUS;
@ -2097,11 +2097,11 @@ class GServer
// Test for Statusnet
$curlResult = DI::httpClient()->get($url . '/api/statusnet/version.json', HttpClientAccept::JSON);
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') &&
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) {
// Remove junk that some GNU Social servers return
$serverdata['version'] = str_replace(chr(239).chr(187).chr(191), '', $curlResult->getBody());
$serverdata['version'] = str_replace(chr(239).chr(187).chr(191), '', $curlResult->getBodyString());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"');
@ -2148,7 +2148,7 @@ class GServer
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
$data = json_decode($curlResult->getBodyString(), true);
if (empty($data) || empty($data['version'])) {
return $serverdata;
}
@ -2466,7 +2466,7 @@ class GServer
$api = 'https://instances.social/api/1.0/instances/list?count=0';
$curlResult = DI::httpClient()->get($api, HttpClientAccept::JSON, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]);
if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true);
$servers = json_decode($curlResult->getBodyString(), true);
if (!empty($servers['instances'])) {
foreach ($servers['instances'] as $server) {

View file

@ -597,7 +597,7 @@ class Photo
if (!empty($image_url)) {
$ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE);
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBody();
$img_str = $ret->getBodyString();
$type = $ret->getContentType();
} else {
$img_str = '';
@ -1047,7 +1047,7 @@ class Photo
if (!empty($image_url)) {
$ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE);
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBody();
$img_str = $ret->getBodyString();
$type = $ret->getContentType();
} else {
$img_str = '';

View file

@ -135,7 +135,7 @@ class Link
}
$fields = ['mimetype' => $curlResult->getHeader('Content-Type')[0]];
$img_str = $curlResult->getBody();
$img_str = $curlResult->getBodyString();
$image = new Image($img_str, Images::getMimeTypeByData($img_str));
if ($image->isValid()) {
$fields['mimetype'] = $image->getType();

View file

@ -208,13 +208,17 @@ class Media
$filetype = !empty($media['mimetype']) ? strtolower(current(explode('/', $media['mimetype']))) : '';
if (($media['type'] == self::IMAGE) || ($filetype == 'image')) {
$imagedata = Images::getInfoFromURLCached($media['url']);
$imagedata = Images::getInfoFromURLCached($media['url'], empty($media['description']));
if ($imagedata) {
$media['mimetype'] = $imagedata['mime'];
$media['size'] = $imagedata['size'];
$media['width'] = $imagedata[0];
$media['height'] = $imagedata[1];
$media['blurhash'] = $imagedata['blurhash'] ?? null;
if (!empty($imagedata['description']) && empty($media['description'])) {
$media['description'] = $imagedata['description'];
Logger::debug('Detected text for image', $media);
}
} else {
Logger::notice('No image data', ['media' => $media]);
}

View file

@ -1393,7 +1393,7 @@ class User
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE);
if ($curlResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBody();
$img_str = $curlResult->getBodyString();
$type = $curlResult->getContentType();
} else {
$img_str = '';
@ -1563,16 +1563,17 @@ class User
/**
* Creates a new user based on a minimal set and sends an email to this user
*
* @param string $name The user's name
* @param string $email The user's email address
* @param string $nick The user's nick name
* @param string $lang The user's language (default is english)
* @param string $name The user's name
* @param string $email The user's email address
* @param string $nick The user's nick name
* @param string $lang The user's language (default is english)
* @param string $avatar URL to an image to use as avatar (default is to prompt user at first login)
* @return bool True, if the user was created successfully
* @throws HTTPException\InternalServerErrorException
* @throws ErrorException
* @throws ImagickException
*/
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT): bool
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT, string $avatar = ''): bool
{
if (empty($name) ||
empty($email) ||
@ -1585,7 +1586,8 @@ class User
'email' => $email,
'nickname' => $nick,
'verified' => 1,
'language' => $lang
'language' => $lang,
'photo' => $avatar
]);
$user = $result['user'];
@ -1607,8 +1609,8 @@ class User
You may also wish to add some basic information to your default profile
(on the "Profiles" page) so that other people can easily find you.
We recommend adding a profile photo, adding some profile "keywords"
(very useful in making new friends) - and perhaps what country you live in;
We recommend adding a profile photo, adding some profile "keywords"
(very useful in making new friends) - and perhaps what country you live in;
if you do not wish to be more specific than that.
We fully respect your right to privacy, and none of these items are necessary.

View file

@ -132,7 +132,7 @@ class MatchInterests extends BaseModule
}
}
$entries = $this->parseContacts(json_decode($result->getBody()), $entries, $limit);
$entries = $this->parseContacts(json_decode($result->getBodyString()), $entries, $limit);
}
if (empty($entries)) {

View file

@ -132,8 +132,8 @@ class Community extends Timeline
$pager = new BoundariesPager(
$this->l10n,
$this->args->getQueryString(),
$items[0]['received'],
$items[count($items) - 1]['received'],
$items[array_key_first($items)]['received'],
$items[array_key_last($items)]['received'],
$this->itemsPerPage
);

View file

@ -155,7 +155,7 @@ class Magic extends BaseModule
System::externalRedirect($dest);
}
$j = json_decode($curlResult->getBody(), true);
$j = json_decode($curlResult->getBodyString(), true);
if (empty($j) || !$j['success']) {
$this->logger->notice('Invalid JSON, redirecting to destination.', ['json' => $j, 'dest' => $dest]);
$this->app->redirect($dest);

View file

@ -154,7 +154,7 @@ class PubSubHubBub extends \Friendica\BaseModule
$separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&';
$fetchResult = $this->httpClient->fetchFull($hub_callback . $separator . $params);
$body = $fetchResult->getBody();
$body = $fetchResult->getBodyString();
$returnCode = $fetchResult->getReturnCode();
// give up if the HTTP return code wasn't a success (2xx)

View file

@ -96,7 +96,7 @@ class Subscribe extends \Friendica\BaseModule
return $o . $this->t('Couldn\'t fetch friends for contact.');
}
$friends = $curlResult->getBody();
$friends = $curlResult->getBodyString();
if (empty($friends)) {
$this->pConfig->delete($uid, 'ostatus', 'legacy_contact');
return $o . $this->t('Couldn\'t fetch following contacts.');

View file

@ -85,7 +85,7 @@ class Proxy extends BaseModule
// Fetch the content with the local user
try {
$fetchResult = HTTPSignature::fetchRaw($request['url'], DI::userSession()->getLocalUserId(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]);
$img_str = $fetchResult->getBody();
$img_str = $fetchResult->getBodyString();
if (!$fetchResult->isSuccess() || empty($img_str)) {
Logger::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);

View file

@ -97,10 +97,9 @@ interface ICanHandleHttpResponses
/**
* Getter for body
*
* @see MessageInterface::getBody()
* @return string
*/
public function getBody();
public function getBodyString();
/**
* @return boolean

View file

@ -73,7 +73,7 @@ class HttpClient implements ICanSendHttpRequests
throw new \InvalidArgumentException('Unable to retrieve the host in URL: ' . $url);
}
if(!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A + DNS_AAAA)) {
if(!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A) && !@dns_get_record($host . '.', DNS_AAAA)) {
$this->logger->debug('URL cannot be resolved.', ['url' => $url]);
$this->profiler->stopRecording();
return CurlResult::createErrorCurl($this->logger, $url);
@ -271,7 +271,7 @@ class HttpClient implements ICanSendHttpRequests
{
$ret = $this->fetchFull($url, $accept_content, $timeout, $cookiejar);
return $ret->getBody();
return $ret->getBodyString();
}
/**

View file

@ -330,7 +330,7 @@ class CurlResult implements ICanHandleHttpResponses
}
/** {@inheritDoc} */
public function getBody(): string
public function getBodyString(): string
{
return $this->body;
}

View file

@ -163,8 +163,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
return $this->isTimeout;
}
/// @todo - fix mismatching use of "getBody()" as string here and parent "getBody()" as streaminterface
public function getBody(): string
public function getBodyString(): string
{
return (string) parent::getBody();
}

View file

@ -225,7 +225,7 @@ class Probe
$curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isSuccess()) {
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
$xrd = XML::parseString($xml, true);
if (!empty($url)) {
$host_url = 'https://' . $host;
@ -250,7 +250,7 @@ class Probe
return [];
}
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
$xrd = XML::parseString($xml, true);
$host_url = 'http://'.$host;
}
@ -426,7 +426,7 @@ class Probe
if (!empty($data['baseurl']) && empty($data['gsid'])) {
$data['gsid'] = GServer::getID($data['baseurl']);
}
}
// Ensure that local connections always are DFRN
if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) {
@ -459,7 +459,7 @@ class Probe
return false;
}
$body = $curlResult->getBody();
$body = $curlResult->getBodyString();
if (empty($body)) {
return false;
}
@ -865,7 +865,7 @@ class Probe
if ($curlResult->isTimeout()) {
return $data;
}
$content = $curlResult->getBody();
$content = $curlResult->getBodyString();
if (!$content) {
return $data;
}
@ -971,7 +971,7 @@ class Probe
self::$isTimeout = true;
return [];
}
$data = $curlResult->getBody();
$data = $curlResult->getBodyString();
$webfinger = json_decode($data, true);
if (!empty($webfinger)) {
@ -1040,7 +1040,7 @@ class Probe
self::$isTimeout = true;
return $data;
}
$content = $curlResult->getBody();
$content = $curlResult->getBodyString();
if (!$content) {
Logger::info('Empty body', ['url' => $noscrape_url]);
return $data;
@ -1303,7 +1303,7 @@ class Probe
self::$isTimeout = true;
return [];
}
$content = $curlResult->getBody();
$content = $curlResult->getBodyString();
if (empty($content)) {
return [];
}
@ -1580,7 +1580,7 @@ class Probe
return $short ? false : [];
}
Logger::debug('Fetched public key', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $pubkey]);
$pubkey = $curlResult->getBody();
$pubkey = $curlResult->getBodyString();
}
try {
@ -1612,7 +1612,7 @@ class Probe
self::$isTimeout = true;
return [];
}
$feed = $curlResult->getBody();
$feed = $curlResult->getBodyString();
$feed_data = Feed::import($feed);
if (!$feed_data) {
return [];
@ -1660,12 +1660,12 @@ class Probe
private static function pumpioProfileData(string $profile_link, string $baseurl): array
{
$curlResult = DI::httpClient()->get($profile_link, HttpClientAccept::HTML);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
return [];
}
$doc = new DOMDocument();
if (!@$doc->loadHTML($curlResult->getBody())) {
if (!@$doc->loadHTML($curlResult->getBodyString())) {
return [];
}
@ -1887,7 +1887,7 @@ class Probe
return [];
}
$feed = $curlResult->getBody();
$feed = $curlResult->getBodyString();
$feed_data = Feed::import($feed);
if (!$feed_data) {
@ -2112,8 +2112,8 @@ class Probe
$curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$noscrape = json_decode($curlResult->getBody(), true);
if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) {
$noscrape = json_decode($curlResult->getBodyString(), true);
if (!empty($noscrape) && !empty($noscrape['updated'])) {
return DateTimeFormat::utc($noscrape['updated'], DateTimeFormat::MYSQL);
}
@ -2187,12 +2187,12 @@ class Probe
{
// Search for the newest entry in the feed
$curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML);
if (!$curlResult->isSuccess() || !$curlResult->getBody()) {
if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) {
return '';
}
$doc = new DOMDocument();
@$doc->loadXML($curlResult->getBody());
@$doc->loadXML($curlResult->getBodyString());
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');

View file

@ -614,7 +614,7 @@ class Processor
}
if ($curlResult->isSuccess()) {
$object = json_decode($curlResult->getBody(), true);
$object = json_decode($curlResult->getBodyString(), true);
if (!empty($object)) {
$activity = JsonLD::compact($object);
if (JsonLD::fetchElement($activity, '@type') == 'as:Tombstone') {
@ -1584,7 +1584,7 @@ class Processor
return '';
}
$body = $curlResult->getBody();
$body = $curlResult->getBodyString();
if (!$curlResult->isSuccess() || empty($body)) {
if (in_array($curlResult->getReturnCode(), [403, 404, 406, 410])) {
return null;

View file

@ -1012,7 +1012,7 @@ class DFRN
$content_type = ($public_batch ? 'application/magic-envelope+xml' : 'application/json');
$postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type]);
$xml = $postResult->getBody();
$xml = $postResult->getBodyString();
$curl_stat = $postResult->getReturnCode();
if (!empty($contact['gsid']) && ($postResult->isTimeout() || empty($curl_stat))) {

View file

@ -736,7 +736,7 @@ class OStatus
$stored = false;
$curlResult = DI::httpClient()->get($related, HttpClientAccept::ATOM_XML);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
return;
}
@ -745,12 +745,12 @@ class OStatus
if ($curlResult->inHeader('Content-Type') &&
in_array('application/atom+xml', $curlResult->getHeader('Content-Type'))) {
Logger::info('Directly fetched XML for URI ' . $related_uri);
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
}
if ($xml == '') {
$doc = new DOMDocument();
if (!@$doc->loadHTML($curlResult->getBody())) {
if (!@$doc->loadHTML($curlResult->getBodyString())) {
return;
}
$xpath = new DOMXPath($doc);
@ -770,7 +770,7 @@ class OStatus
if ($curlResult->isSuccess()) {
Logger::info('Fetched XML for URI ' . $related_uri);
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
}
}
}
@ -782,7 +782,7 @@ class OStatus
if ($curlResult->isSuccess()) {
Logger::info('GNU Social workaround to fetch XML for URI ' . $related_uri);
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
}
}
@ -793,7 +793,7 @@ class OStatus
if ($curlResult->isSuccess()) {
Logger::info('GNU Social workaround 2 to fetch XML for URI ' . $related_uri);
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
}
}

View file

@ -250,7 +250,7 @@ class ExAuth
return false;
}
$json = @json_decode($curlResult->getBody());
$json = @json_decode($curlResult->getBodyString());
if (!is_object($json)) {
return false;
}

View file

@ -433,12 +433,12 @@ class HTTPSignature
return [];
}
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
Logger::debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]);
return [];
}
$content = json_decode($curlResult->getBody(), true);
$content = json_decode($curlResult->getBodyString(), true);
if (empty($content) || !is_array($content)) {
return [];
}

View file

@ -21,6 +21,7 @@
namespace Friendica\Util;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Photo;
@ -181,10 +182,11 @@ class Images
* Gets info array from given URL, cached data has priority
*
* @param string $url
* @param bool $ocr
* @return array Info
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getInfoFromURLCached(string $url): array
public static function getInfoFromURLCached(string $url, bool $ocr = false): array
{
$data = [];
@ -192,12 +194,12 @@ class Images
return $data;
}
$cacheKey = 'getInfoFromURL:' . sha1($url);
$cacheKey = 'getInfoFromURL:' . sha1($url . $ocr);
$data = DI::cache()->get($cacheKey);
if (empty($data) || !is_array($data)) {
$data = self::getInfoFromURL($url);
$data = self::getInfoFromURL($url, $ocr);
DI::cache()->set($cacheKey, $data);
}
@ -209,10 +211,11 @@ class Images
* Gets info from URL uncached
*
* @param string $url
* @param bool $ocr
* @return array Info array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getInfoFromURL(string $url): array
public static function getInfoFromURL(string $url, bool $ocr = false): array
{
$data = [];
@ -257,6 +260,14 @@ class Images
if ($image->isValid()) {
$data['blurhash'] = $image->getBlurHash();
if ($ocr) {
$media = ['img_str' => $img_str];
Hook::callAll('ocr-detection', $media);
if (!empty($media['description'])) {
$data['description'] = $media['description'];
}
}
}
$data['size'] = $filesize;

View file

@ -238,7 +238,7 @@ class ParseUrl
}
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
return $siteinfo;
}
@ -252,7 +252,7 @@ class ParseUrl
}
}
$body = $curlResult->getBody();
$body = $curlResult->getBodyString();
if ($do_oembed) {
$oembed_data = OEmbed::fetchURL($url, false, false);

View file

@ -70,7 +70,7 @@ class CheckRelMeProfileLink
return;
}
$content = $curlResult->getBody();
$content = $curlResult->getBodyString();
if (!$content) {
Logger::notice('Empty body of the fetched homepage link). Cannot verify the relation to profile of UID %s.', ['uid' => $uid, 'owner homepage' => $owner['homepage']]);
return;

View file

@ -172,7 +172,7 @@ class OnePoll
return false;
}
$xml = $curlResult->getBody();
$xml = $curlResult->getBodyString();
if (empty($xml)) {
Logger::notice('Empty content', ['id' => $contact['id'], 'url' => $contact['poll']]);
return false;

View file

@ -45,12 +45,12 @@ class UpdateServerPeers
}
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON);
if (!$ret->isSuccess() || empty($ret->getBody())) {
if (!$ret->isSuccess() || empty($ret->getBodyString())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
return;
}
$peers = json_decode($ret->getBody());
$peers = json_decode($ret->getBodyString());
if (empty($peers) || !is_array($peers)) {
Logger::info('Server does not have any peers listed', ['url' => $url]);
return;