Merge remote-tracking branch 'upstream/2022.09-rc' into quote-uri-id

This commit is contained in:
Michael 2022-10-14 19:11:15 +00:00
commit 88aceeb27f
5 changed files with 59 additions and 11 deletions

View file

@ -656,8 +656,12 @@ class Item
*/
public function createSharedBlockByArray(array $item): string
{
if (!in_array($item['network'] ?? '', Protocol::FEDERATED)) {
if ($item['network'] == Protocol::FEED) {
return PageInfo::getFooterFromUrl($item['plink']);
} elseif (!in_array($item['network'] ?? '', Protocol::FEDERATED)) {
$item['guid'] = '';
$item['uri'] = '';
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
}
$shared_content = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']);
@ -666,8 +670,14 @@ class Item
$shared_content .= '[h3]' . $item['title'] . "[/h3]\n";
}
$shared = BBCode::fetchShareAttributes($item['body']);
// If it is a reshared post then reformat it to avoid display problems with two share elements
if (Diaspora::isReshare($item['body'], false)) {
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid']))) {
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
}
$item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB));
}

View file

@ -1680,11 +1680,9 @@ class Contact
/**
* Return the photo path for a given contact array in the given size
*
* @param array $contact contact array
* @param string $field Fieldname of the photo in the contact array
* @param array $contact contact array
* @param string $size Size of the avatar picture
* @param string $avatar Avatar path that is displayed when no photo had been found
* @param bool $no_update Don't perfom an update if no cached avatar was found
* @param bool $no_update Don't perfom an update if no cached avatar was found
* @return string photo path
*/
private static function getAvatarPath(array $contact, string $size, bool $no_update = false): string
@ -1711,7 +1709,7 @@ class Contact
}
}
return self::getAvatarUrlForId($contact['id'], $size, $contact['updated'] ?? '');
return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated'] ?? '');
}
/**

View file

@ -580,7 +580,7 @@ class Event
$last_date = '';
$fmt = DI::l10n()->t('l, F j');
foreach ($event_result as $event) {
$item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]);
$item = Post::selectFirst(['plink', 'author-name', 'author-network', 'author-id', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]);
if (!DBA::isResult($item)) {
// Using default values when no item had been found
$item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC, 'uri-id' => ($event['uri-id'] ?? 0)];

View file

@ -648,11 +648,13 @@ class Media
/**
* Add media attachments to the body
*
* @param int $uriid
* @param int $uriid
* @param string $body
* @param array $types
*
* @return string body
*/
public static function addAttachmentsToBody(int $uriid, string $body = ''): string
public static function addAttachmentsToBody(int $uriid, string $body = '', array $types = [self::IMAGE, self::AUDIO, self::VIDEO]): string
{
if (empty($body)) {
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
@ -665,7 +667,7 @@ class Media
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
foreach (self::getByURIId($uriid, $types) as $media) {
if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
continue;
}