mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:40:16 +00:00
Merge pull request #14610 from annando/media-post
Improved check for attached Fediverse posts
This commit is contained in:
commit
775624ec24
2 changed files with 32 additions and 1 deletions
|
@ -24,11 +24,13 @@ use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
use Friendica\Protocol\ATProtocol;
|
||||||
use Friendica\Util\Images;
|
use Friendica\Util\Images;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\ParseUrl;
|
use Friendica\Util\ParseUrl;
|
||||||
use Friendica\Util\Proxy;
|
use Friendica\Util\Proxy;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use GuzzleHttp\Psr7\Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Media
|
* Class Media
|
||||||
|
@ -237,7 +239,7 @@ class Media
|
||||||
$media = self::addAccount($media);
|
$media = self::addAccount($media);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($media['type'], [self::ACTIVITY, self::LD, self::JSON])) {
|
if (in_array($media['type'], [self::ACTIVITY, self::LD, self::JSON]) || self::isFederatedServer($media['url'])) {
|
||||||
$media = self::addActivity($media);
|
$media = self::addActivity($media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +250,20 @@ class Media
|
||||||
return $media;
|
return $media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function isFederatedServer(string $url): bool
|
||||||
|
{
|
||||||
|
$baseurl = Network::getBaseUrl(new Uri($url));
|
||||||
|
if (empty($baseurl)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings::compareLink($baseurl, ATProtocol::WEB)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBA::exists('gserver', ['nurl' => Strings::normaliseLink($baseurl), 'network' => Protocol::FEDERATED]);
|
||||||
|
}
|
||||||
|
|
||||||
private static function addPreviewData(array $media): array
|
private static function addPreviewData(array $media): array
|
||||||
{
|
{
|
||||||
if (!empty($media['preview-width']) && !empty($media['preview-height'])) {
|
if (!empty($media['preview-width']) && !empty($media['preview-height'])) {
|
||||||
|
|
|
@ -682,4 +682,19 @@ class Network
|
||||||
|
|
||||||
return (string)Uri::fromParts($parts);
|
return (string)Uri::fromParts($parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get base url without a path, fragment or query
|
||||||
|
*
|
||||||
|
* @param UriInterface $uri
|
||||||
|
* @return string baseurl
|
||||||
|
*/
|
||||||
|
public static function getBaseUrl(UriInterface $uri): string
|
||||||
|
{
|
||||||
|
return $uri
|
||||||
|
->withUserInfo('')
|
||||||
|
->withQuery('')
|
||||||
|
->withFragment('')
|
||||||
|
->withPath('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue