mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-12 01:54:26 +02:00
Merge remote-tracking branch 'upstream/2023.09-rc' into smilies
This commit is contained in:
commit
19529e2aa1
417 changed files with 48140 additions and 31688 deletions
|
@ -241,12 +241,20 @@ class ActivityPub
|
|||
/**
|
||||
* Fetch items from AP endpoints
|
||||
*
|
||||
* @param string $url Address of the endpoint
|
||||
* @param integer $uid Optional user id
|
||||
* @param string $url Address of the endpoint
|
||||
* @param integer $uid Optional user id
|
||||
* @param integer $start_timestamp Internally used parameter to stop fetching after some time
|
||||
* @return array Endpoint items
|
||||
*/
|
||||
public static function fetchItems(string $url, int $uid = 0): array
|
||||
public static function fetchItems(string $url, int $uid = 0, int $start_timestamp = 0): array
|
||||
{
|
||||
$start_timestamp = $start_timestamp ?: time();
|
||||
|
||||
if ((time() - $start_timestamp) > 60) {
|
||||
Logger::info('Fetch time limit reached', ['url' => $url, 'uid' => $uid]);
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = self::fetchContent($url, $uid);
|
||||
if (empty($data)) {
|
||||
return [];
|
||||
|
@ -257,13 +265,13 @@ class ActivityPub
|
|||
} elseif (!empty($data['first']['orderedItems'])) {
|
||||
$items = $data['first']['orderedItems'];
|
||||
} elseif (!empty($data['first']) && is_string($data['first']) && ($data['first'] != $url)) {
|
||||
return self::fetchItems($data['first'], $uid);
|
||||
return self::fetchItems($data['first'], $uid, $start_timestamp);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!empty($data['next']) && is_string($data['next'])) {
|
||||
$items = array_merge($items, self::fetchItems($data['next'], $uid));
|
||||
$items = array_merge($items, self::fetchItems($data['next'], $uid, $start_timestamp));
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
|
|
@ -1652,7 +1652,19 @@ class Processor
|
|||
$attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
|
||||
$authorid = Contact::getIdForURL($attributed_to);
|
||||
|
||||
$body = HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value') ?? '');
|
||||
$content = JsonLD::fetchElement($activity['as:object'], 'as:name', '@value') ?? '';
|
||||
$content .= ' ' . JsonLD::fetchElement($activity['as:object'], 'as:summary', '@value') ?? '';
|
||||
$content .= ' ' . HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value') ?? '');
|
||||
|
||||
$attachments = JsonLD::fetchElementArray($activity['as:object'], 'as:attachment') ?? [];
|
||||
foreach ($attachments as $media) {
|
||||
if (!empty($media['as:summary'])) {
|
||||
$content .= ' ' . JsonLD::fetchElement($media, 'as:summary', '@value');
|
||||
}
|
||||
if (!empty($media['as:name'])) {
|
||||
$content .= ' ' . JsonLD::fetchElement($media, 'as:name', '@value');
|
||||
}
|
||||
}
|
||||
|
||||
$messageTags = [];
|
||||
$tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []);
|
||||
|
@ -1665,7 +1677,7 @@ class Processor
|
|||
}
|
||||
}
|
||||
|
||||
return Relay::isSolicitedPost($messageTags, $body, $authorid, $id, Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0);
|
||||
return Relay::isSolicitedPost($messageTags, $content, $authorid, $id, Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1752,7 +1752,7 @@ class Transmitter
|
|||
|
||||
$body = BBCode::setMentionsToNicknames($body);
|
||||
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
|
||||
if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
|
||||
$real_quote = true;
|
||||
$data['quoteUrl'] = $item['quote-uri'];
|
||||
|
@ -1772,7 +1772,7 @@ class Transmitter
|
|||
if (!empty($language)) {
|
||||
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
|
||||
$richbody = Post\Media::removeFromEndOfBody($richbody);
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
|
||||
if ($real_quote) {
|
||||
$richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
|
||||
} else {
|
||||
|
@ -1784,7 +1784,7 @@ class Transmitter
|
|||
$data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
|
||||
}
|
||||
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
|
||||
$source = DI::contentItem()->addSharedPost($item, $item['body']);
|
||||
} else {
|
||||
$source = $item['body'];
|
||||
|
|
|
@ -88,7 +88,7 @@ class DFRN
|
|||
$contact['senderName'] = $contact['name'];
|
||||
|
||||
if ($uid != 0) {
|
||||
$condition = ['uid' => $uid, 'account_expired' => false, 'account_removed' => false];
|
||||
$condition = ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
|
||||
$user = DBA::selectFirst('user', [], $condition);
|
||||
if (!DBA::isResult($user)) {
|
||||
return [];
|
||||
|
|
|
@ -3062,10 +3062,7 @@ class Diaspora
|
|||
// If the item belongs to a user, we take this user id.
|
||||
if ($item['uid'] == 0) {
|
||||
// @todo Possibly use an administrator account?
|
||||
$condition = [
|
||||
'verified' => true, 'blocked' => false,
|
||||
'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON
|
||||
];
|
||||
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON];
|
||||
$first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]);
|
||||
$owner = User::getOwnerDataById($first_user['uid']);
|
||||
} else {
|
||||
|
|
|
@ -87,24 +87,14 @@ class Relay
|
|||
|
||||
$body = ActivityPub\Processor::normalizeMentionLinks($body);
|
||||
|
||||
$systemTags = [];
|
||||
$userTags = [];
|
||||
$denyTags = [];
|
||||
|
||||
if ($scope == self::SCOPE_TAGS) {
|
||||
$server_tags = $config->get('system', 'relay_server_tags');
|
||||
$tagitems = explode(',', mb_strtolower($server_tags));
|
||||
foreach ($tagitems as $tag) {
|
||||
$systemTags[] = trim($tag, '# ');
|
||||
}
|
||||
|
||||
if ($config->get('system', 'relay_user_tags')) {
|
||||
$userTags = Search::getUserTags();
|
||||
}
|
||||
$tagList = self::getSubscribedTags();
|
||||
} else {
|
||||
$tagList = [];
|
||||
}
|
||||
|
||||
$tagList = array_unique(array_merge($systemTags, $userTags));
|
||||
|
||||
$deny_tags = $config->get('system', 'relay_deny_tags');
|
||||
$tagitems = explode(',', mb_strtolower($deny_tags));
|
||||
foreach ($tagitems as $tag) {
|
||||
|
@ -136,7 +126,7 @@ class Relay
|
|||
}
|
||||
}
|
||||
|
||||
if (!self::isWantedLanguage($body)) {
|
||||
if (!self::isWantedLanguage($body, 0, $authorid)) {
|
||||
Logger::info('Unwanted or Undetected language found - rejected', ['network' => $network, 'url' => $url, 'causer' => $causer, 'tags' => $tags]);
|
||||
return false;
|
||||
}
|
||||
|
@ -150,13 +140,38 @@ class Relay
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of subscribed tags by both the users and the tags that are defined by the admin
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedTags(): array
|
||||
{
|
||||
$systemTags = [];
|
||||
$server_tags = DI::config()->get('system', 'relay_server_tags');
|
||||
|
||||
foreach (explode(',', mb_strtolower($server_tags)) as $tag) {
|
||||
$systemTags[] = trim($tag, '# ');
|
||||
}
|
||||
|
||||
if (DI::config()->get('system', 'relay_user_tags')) {
|
||||
$userTags = Search::getUserTags();
|
||||
} else {
|
||||
$userTags = [];
|
||||
}
|
||||
|
||||
return array_unique(array_merge($systemTags, $userTags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the language of a post and decide if the post should be accepted
|
||||
*
|
||||
* @param string $body
|
||||
* @param int $uri_id
|
||||
* @param int $author_id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isWantedLanguage(string $body)
|
||||
public static function isWantedLanguage(string $body, int $uri_id = 0, int $author_id = 0)
|
||||
{
|
||||
if (empty($body) || Smilies::isEmojiPost($body)) {
|
||||
Logger::debug('Empty body or only emojis', ['body' => $body]);
|
||||
|
@ -164,7 +179,7 @@ class Relay
|
|||
}
|
||||
|
||||
$languages = [];
|
||||
foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
|
||||
foreach (Item::getLanguageArray($body, 10, $uri_id, $author_id) as $language => $reliability) {
|
||||
if ($reliability > 0) {
|
||||
$languages[] = $language;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue