Fix code style

This commit is contained in:
Art4 2025-01-06 21:16:31 +00:00
parent f7dbb06d59
commit a6aa53cd25
4 changed files with 283 additions and 287 deletions

View file

@ -46,38 +46,38 @@ use LanguageDetection\Language;
class Item class Item
{ {
// Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types // Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types
const PT_ARTICLE = 0; const PT_ARTICLE = 0;
const PT_NOTE = 1; const PT_NOTE = 1;
const PT_PAGE = 2; const PT_PAGE = 2;
const PT_IMAGE = 16; const PT_IMAGE = 16;
const PT_AUDIO = 17; const PT_AUDIO = 17;
const PT_VIDEO = 18; const PT_VIDEO = 18;
const PT_DOCUMENT = 19; const PT_DOCUMENT = 19;
const PT_EVENT = 32; const PT_EVENT = 32;
const PT_POLL = 33; const PT_POLL = 33;
const PT_PERSONAL_NOTE = 128; const PT_PERSONAL_NOTE = 128;
// Posting reasons (Why had a post been stored for a user?) // Posting reasons (Why had a post been stored for a user?)
const PR_NONE = 0; const PR_NONE = 0;
const PR_TAG = 64; const PR_TAG = 64;
const PR_TO = 65; const PR_TO = 65;
const PR_CC = 66; const PR_CC = 66;
const PR_BTO = 67; const PR_BTO = 67;
const PR_BCC = 68; const PR_BCC = 68;
const PR_FOLLOWER = 69; const PR_FOLLOWER = 69;
const PR_ANNOUNCEMENT = 70; const PR_ANNOUNCEMENT = 70;
const PR_COMMENT = 71; const PR_COMMENT = 71;
const PR_STORED = 72; const PR_STORED = 72;
const PR_GLOBAL = 73; const PR_GLOBAL = 73;
const PR_RELAY = 74; const PR_RELAY = 74;
const PR_FETCHED = 75; const PR_FETCHED = 75;
const PR_COMPLETION = 76; const PR_COMPLETION = 76;
const PR_DIRECT = 77; const PR_DIRECT = 77;
const PR_ACTIVITY = 78; const PR_ACTIVITY = 78;
const PR_DISTRIBUTE = 79; const PR_DISTRIBUTE = 79;
const PR_PUSHED = 80; const PR_PUSHED = 80;
const PR_LOCAL = 81; const PR_LOCAL = 81;
const PR_AUDIENCE = 82; const PR_AUDIENCE = 82;
// system.accept_only_sharer setting values // system.accept_only_sharer setting values
const COMPLETION_NONE = 1; const COMPLETION_NONE = 1;
@ -146,8 +146,8 @@ class Item
]; ];
// Privacy levels // Privacy levels
const PUBLIC = 0; const PUBLIC = 0;
const PRIVATE = 1; const PRIVATE = 1;
const UNLISTED = 2; const UNLISTED = 2;
// Item weight for query ordering // Item weight for query ordering
@ -493,7 +493,7 @@ class Item
// Is it in the format data@host.tld? - Used for mail contacts // Is it in the format data@host.tld? - Used for mail contacts
if (empty($prefix_host) && !empty($item['author-link']) && strstr($item['author-link'], '@')) { if (empty($prefix_host) && !empty($item['author-link']) && strstr($item['author-link'], '@')) {
$mailparts = explode('@', $item['author-link']); $mailparts = explode('@', $item['author-link']);
$prefix_host = array_pop($mailparts); $prefix_host = array_pop($mailparts);
} }
} }
@ -597,7 +597,7 @@ class Item
} }
$condition = [ $condition = [
'uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'uri-id' => $item['uri-id'], 'uid' => $item['uid'],
'network' => [$item['network'], Protocol::DFRN] 'network' => [$item['network'], Protocol::DFRN]
]; ];
if (Post::exists($condition)) { if (Post::exists($condition)) {
@ -682,7 +682,7 @@ class Item
} }
$condition = [ $condition = [
'verb' => Activity::FOLLOW, 'uid' => $item['uid'], 'verb' => Activity::FOLLOW, 'uid' => $item['uid'],
'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id'] 'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id']
]; ];
if (Post::exists($condition)) { if (Post::exists($condition)) {
@ -717,10 +717,10 @@ class Item
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives // We only log the entries with a different user id than 0. Otherwise we would have too many false positives
if ($item['uid'] != 0) { if ($item['uid'] != 0) {
Logger::notice('Item already existed for user', [ Logger::notice('Item already existed for user', [
'uri-id' => $item['uri-id'], 'uri-id' => $item['uri-id'],
'uid' => $item['uid'], 'uid' => $item['uid'],
'network' => $item['network'], 'network' => $item['network'],
'existing_id' => $existing['id'], 'existing_id' => $existing['id'],
'existing_network' => $existing['network'] 'existing_network' => $existing['network']
]); ]);
} }
@ -767,8 +767,8 @@ class Item
'wall', 'private', 'origin', 'author-id' 'wall', 'private', 'origin', 'author-id'
]; ];
$condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']]; $condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$parent = Post::selectFirst($fields, $condition, $params); $parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) { if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
$stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]); $stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]);
@ -796,11 +796,11 @@ class Item
} }
$condition = [ $condition = [
'uri-id' => $parent['parent-uri-id'], 'uri-id' => $parent['parent-uri-id'],
'parent-uri-id' => $parent['parent-uri-id'], 'parent-uri-id' => $parent['parent-uri-id'],
'uid' => $parent['uid'] 'uid' => $parent['uid']
]; ];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$toplevel_parent = Post::selectFirst($fields, $condition, $params); $toplevel_parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($toplevel_parent) && $item['origin']) { if (!DBA::isResult($toplevel_parent) && $item['origin']) {
@ -885,7 +885,7 @@ class Item
$uid = intval($item['uid']); $uid = intval($item['uid']);
$item['guid'] = self::guid($item, $notify); $item['guid'] = self::guid($item, $notify);
$item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255); $item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255);
// Store URI data // Store URI data
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
@ -991,13 +991,13 @@ class Item
$item['gravity'] = self::getGravity($item); $item['gravity'] = self::getGravity($item);
$default = [ $default = [
'url' => $item['author-link'], 'name' => $item['author-name'], 'url' => $item['author-link'], 'name' => $item['author-name'],
'photo' => $item['author-avatar'], 'network' => $item['network'] 'photo' => $item['author-avatar'], 'network' => $item['network']
]; ];
$item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default); $item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default);
$default = [ $default = [
'url' => $item['owner-link'], 'name' => $item['owner-name'], 'url' => $item['owner-link'], 'name' => $item['owner-name'],
'photo' => $item['owner-avatar'], 'network' => $item['network'] 'photo' => $item['owner-avatar'], 'network' => $item['network']
]; ];
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default); $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
@ -1073,7 +1073,7 @@ class Item
// Update the contact relations // Update the contact relations
Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']); Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']);
} else { } else {
$parent_id = 0; $parent_id = 0;
$parent_origin = $item['origin']; $parent_origin = $item['origin'];
if ($item['wall'] && empty($item['context'])) { if ($item['wall'] && empty($item['context'])) {
@ -1121,7 +1121,7 @@ class Item
} }
if ($notify && $post_local) { if ($notify && $post_local) {
$item['edit'] = false; $item['edit'] = false;
$item['parent'] = $parent_id; $item['parent'] = $parent_id;
// Trigger automatic reactions for addons // Trigger automatic reactions for addons
@ -1132,8 +1132,8 @@ class Item
// We have to tell the hooks who we are - this really should be improved // We have to tell the hooks who we are - this really should be improved
if (!DI::userSession()->getLocalUserId()) { if (!DI::userSession()->getLocalUserId()) {
$_SESSION['authenticated'] = true; $_SESSION['authenticated'] = true;
$_SESSION['uid'] = $uid; $_SESSION['uid'] = $uid;
$dummy_session = true; $dummy_session = true;
} else { } else {
$dummy_session = false; $dummy_session = false;
} }
@ -1251,9 +1251,9 @@ class Item
$ev['guid'] = $item['guid']; $ev['guid'] = $item['guid'];
$ev['plink'] = $item['plink']; $ev['plink'] = $item['plink'];
$ev['network'] = $item['network']; $ev['network'] = $item['network'];
$ev['protocol'] = $item['protocol'] ?? Conversation::PARCEL_UNKNOWN; $ev['protocol'] = $item['protocol'] ?? Conversation::PARCEL_UNKNOWN;
$ev['direction'] = $item['direction'] ?? Conversation::UNKNOWN; $ev['direction'] = $item['direction'] ?? Conversation::UNKNOWN;
$ev['source'] = $item['source'] ?? ''; $ev['source'] = $item['source'] ?? '';
$event = DBA::selectFirst('event', ['id'], ['uri' => $item['uri'], 'uid' => $item['uid']]); $event = DBA::selectFirst('event', ['id'], ['uri' => $item['uri'], 'uid' => $item['uid']]);
if (DBA::isResult($event)) { if (DBA::isResult($event)) {
@ -1261,7 +1261,7 @@ class Item
} }
$event_id = Event::store($ev); $event_id = Event::store($ev);
$item = Event::getItemArrayForImportedId($event_id, $item); $item = Event::getItemArrayForImportedId($event_id, $item);
Logger::info('Event was stored', ['id' => $event_id]); Logger::info('Event was stored', ['id' => $event_id]);
} }
@ -1543,7 +1543,7 @@ class Item
$count = 0; $count = 0;
foreach (DI::userDefinedChannel()->getMatchingChannelUsers($engagement['searchtext'], $language, $tags, $engagement['media-type'], $item['owner-id'], $reshare_id) as $uid) { foreach (DI::userDefinedChannel()->getMatchingChannelUsers($engagement['searchtext'], $language, $tags, $engagement['media-type'], $item['owner-id'], $reshare_id) as $uid) {
$condition = [ $condition = [
'verb' => Activity::ANNOUNCE, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
'author-id' => Contact::getPublicIdByUserId($uid), 'uid' => $uid, 'thr-parent-id' => $uri_id 'author-id' => Contact::getPublicIdByUserId($uid), 'uid' => $uid, 'thr-parent-id' => $uri_id
]; ];
if (!Post::exists($condition)) { if (!Post::exists($condition)) {
@ -1633,7 +1633,7 @@ class Item
} }
$self_contact = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]); $self_contact = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);
$self = !empty($self_contact) ? $self_contact['id'] : 0; $self = !empty($self_contact) ? $self_contact['id'] : 0;
$cid = Contact::getIdForURL($author['url'], $item['uid']); $cid = Contact::getIdForURL($author['url'], $item['uid']);
if (empty($cid) || (!Contact::isSharing($cid, $item['uid']) && ($cid != $self))) { if (empty($cid) || (!Contact::isSharing($cid, $item['uid']) && ($cid != $self))) {
@ -1672,7 +1672,7 @@ class Item
foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) { foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) {
if (!empty($languages)) { if (!empty($languages)) {
$keep = false; $keep = false;
$user_languages = User::getWantedLanguages($uid); $user_languages = User::getWantedLanguages($uid);
foreach ($user_languages as $language) { foreach ($user_languages as $language) {
if (in_array($language, $languages)) { if (in_array($language, $languages)) {
@ -1706,7 +1706,7 @@ class Item
public static function distribute(int $itemid, string $signed_text = '') public static function distribute(int $itemid, string $signed_text = '')
{ {
$condition = ["`id` IN (SELECT `parent` FROM `post-user-view` WHERE `id` = ?)", $itemid]; $condition = ["`id` IN (SELECT `parent` FROM `post-user-view` WHERE `id` = ?)", $itemid];
$parent = Post::selectFirst(['owner-id'], $condition); $parent = Post::selectFirst(['owner-id'], $condition);
if (!DBA::isResult($parent)) { if (!DBA::isResult($parent)) {
Logger::warning('Item not found', ['condition' => $condition]); Logger::warning('Item not found', ['condition' => $condition]);
return; return;
@ -1714,7 +1714,7 @@ class Item
// Only distribute public items from native networks // Only distribute public items from native networks
$condition = [ $condition = [
'id' => $itemid, 'uid' => 0, 'id' => $itemid, 'uid' => 0,
'network' => array_merge(Protocol::FEDERATED, ['']), 'network' => array_merge(Protocol::FEDERATED, ['']),
'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED] 'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]
]; ];
@ -1735,7 +1735,7 @@ class Item
} }
$condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; $condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
$contacts = DBA::select('contact', ['uid'], $condition); $contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if ($contact['uid'] == 0) { if ($contact['uid'] == 0) {
continue; continue;
@ -1746,7 +1746,7 @@ class Item
DBA::close($contacts); DBA::close($contacts);
$condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; $condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
$contacts = DBA::select('contact', ['uid'], $condition); $contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if ($contact['uid'] == 0) { if ($contact['uid'] == 0) {
continue; continue;
@ -1758,7 +1758,7 @@ class Item
if (!empty($owner['alias'])) { if (!empty($owner['alias'])) {
$condition = ['nurl' => Strings::normaliseLink($owner['alias']), 'rel' => [Contact::SHARING, Contact::FRIEND]]; $condition = ['nurl' => Strings::normaliseLink($owner['alias']), 'rel' => [Contact::SHARING, Contact::FRIEND]];
$contacts = DBA::select('contact', ['uid'], $condition); $contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if ($contact['uid'] == 0) { if ($contact['uid'] == 0) {
continue; continue;
@ -1980,21 +1980,21 @@ class Item
unset($item['postopts']); unset($item['postopts']);
unset($item['inform']); unset($item['inform']);
$item['uid'] = $uid; $item['uid'] = $uid;
$item['origin'] = 0; $item['origin'] = 0;
$item['wall'] = 0; $item['wall'] = 0;
$notify = false; $notify = false;
if ($item['gravity'] == self::GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]); $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$notify = self::isRemoteSelf($contact, $item); $notify = self::isRemoteSelf($contact, $item);
$item['wall'] = (bool)$notify; $item['wall'] = (bool)$notify;
} }
} }
$item['contact-id'] = self::contactId($item); $item['contact-id'] = self::contactId($item);
$distributed = self::insert($item, $notify); $distributed = self::insert($item, $notify);
if (!$distributed) { if (!$distributed) {
Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]); Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]);
@ -2016,9 +2016,9 @@ class Item
*/ */
private static function addShadow(int $itemid) private static function addShadow(int $itemid)
{ {
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id']; $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
$condition = ['id' => $itemid, 'gravity' => self::GRAVITY_PARENT]; $condition = ['id' => $itemid, 'gravity' => self::GRAVITY_PARENT];
$item = Post::selectFirst($fields, $condition); $item = Post::selectFirst($fields, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
return; return;
@ -2030,7 +2030,7 @@ class Item
} }
// Is it a visible public post? // Is it a visible public post?
if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) { if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) {
return; return;
} }
@ -2147,7 +2147,7 @@ class Item
} }
$transmitted = []; $transmitted = [];
foreach ($item['transmitted-languages'] ?? [] as $language) { foreach ($item['transmitted-languages'] ?? [] as $language) {
$transmitted[$language] = 0; $transmitted[$language] = 0;
} }
@ -2280,10 +2280,10 @@ class Item
$previous_block = self::getBlockCode($previous); $previous_block = self::getBlockCode($previous);
} }
$block = (($next != '') && \IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block; $block = (($next != '') && \IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block;
$blocks[$block] = ($blocks[$block] ?? '') . $character; $blocks[$block] = ($blocks[$block] ?? '') . $character;
} else { } else {
$block = self::getBlockCode($character); $block = self::getBlockCode($character);
$blocks[$block] = ($blocks[$block] ?? '') . $character; $blocks[$block] = ($blocks[$block] ?? '') . $character;
} }
} }
@ -2330,7 +2330,7 @@ class Item
public static function getLanguageMessage(array $item): string public static function getLanguageMessage(array $item): string
{ {
$iso639 = new \Matriphe\ISO639\ISO639; $iso639 = new \Matriphe\ISO639\ISO639();
$used_languages = ''; $used_languages = '';
foreach (json_decode($item['language'], true) as $language => $reliability) { foreach (json_decode($item['language'], true) as $language => $reliability) {
@ -2533,7 +2533,7 @@ class Item
} }
$basetag = str_replace('_', ' ', substr($tag, 1)); $basetag = str_replace('_', ' ', substr($tag, 1));
$newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . urlencode($basetag) . ']' . $basetag . '[/url]'; $newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . urlencode($basetag) . ']' . $basetag . '[/url]';
$body = str_replace($tag, $newtag, $body); $body = str_replace($tag, $newtag, $body);
} }
@ -2695,8 +2695,8 @@ class Item
$datarray['contact-id'] = $self['id']; $datarray['contact-id'] = $self['id'];
$datarray['author-name'] = $datarray['owner-name'] = $self['name']; $datarray['author-name'] = $datarray['owner-name'] = $self['name'];
$datarray['author-link'] = $datarray['owner-link'] = $self['url']; $datarray['author-link'] = $datarray['owner-link'] = $self['url'];
$datarray['author-avatar'] = $datarray['owner-avatar'] = $self['thumb']; $datarray['author-avatar'] = $datarray['owner-avatar'] = $self['thumb'];
unset($datarray['edited']); unset($datarray['edited']);
@ -2706,14 +2706,14 @@ class Item
unset($datarray['author-id']); unset($datarray['author-id']);
if ($contact['network'] != Protocol::FEED) { if ($contact['network'] != Protocol::FEED) {
$old_uri_id = $datarray['uri-id'] ?? 0; $old_uri_id = $datarray['uri-id'] ?? 0;
$datarray['guid'] = System::createUUID(); $datarray['guid'] = System::createUUID();
unset($datarray['plink']); unset($datarray['plink']);
$datarray['uri'] = self::newURI($datarray['guid']); $datarray['uri'] = self::newURI($datarray['guid']);
$datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']); $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
$datarray['extid'] = Protocol::DFRN; $datarray['extid'] = Protocol::DFRN;
$urlpart = parse_url($datarray2['author-link']); $urlpart = parse_url($datarray2['author-link']);
$datarray['app'] = $urlpart['host']; $datarray['app'] = $urlpart['host'];
if (!empty($old_uri_id)) { if (!empty($old_uri_id)) {
Post\Media::copy($old_uri_id, $datarray['uri-id']); Post\Media::copy($old_uri_id, $datarray['uri-id']);
} }
@ -2726,7 +2726,7 @@ class Item
Logger::info('remote-self post original item', ['contact' => $contact['url'], 'result' => $result, 'item' => $datarray2]); Logger::info('remote-self post original item', ['contact' => $contact['url'], 'result' => $result, 'item' => $datarray2]);
} else { } else {
$datarray['app'] = 'Feed'; $datarray['app'] = 'Feed';
$result = true; $result = true;
} }
if ($result) { if ($result) {
@ -2756,11 +2756,11 @@ class Item
$site = substr(DI::baseUrl(), strpos(DI::baseUrl(), '://')); $site = substr(DI::baseUrl(), strpos(DI::baseUrl(), '://'));
$orig_body = $s; $orig_body = $s;
$new_body = ''; $new_body = '';
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
while (($img_st_close !== false) && ($img_len !== false)) { while (($img_st_close !== false) && ($img_len !== false)) {
$img_st_close++; // make it point to AFTER the closing bracket $img_st_close++; // make it point to AFTER the closing bracket
@ -2771,13 +2771,13 @@ class Item
if (stristr($image, $site . '/photo/')) { if (stristr($image, $site . '/photo/')) {
// Only embed locally hosted photos // Only embed locally hosted photos
$replace = false; $replace = false;
$i = basename($image); $i = basename($image);
$i = str_replace(['.jpg', '.png', '.gif'], ['', '', ''], $i); $i = str_replace(['.jpg', '.png', '.gif'], ['', '', ''], $i);
$x = strpos($i, '-'); $x = strpos($i, '-');
if ($x) { if ($x) {
$res = substr($i, $x + 1); $res = substr($i, $x + 1);
$i = substr($i, 0, $x); $i = substr($i, 0, $x);
$photo = Photo::getPhotoForUser($uid, $i, $res); $photo = Photo::getPhotoForUser($uid, $i, $res);
if (DBA::isResult($photo)) { if (DBA::isResult($photo)) {
/* /*
@ -2807,7 +2807,7 @@ class Item
if (preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) { if (preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
Logger::info('scaling photo'); Logger::info('scaling photo');
$width = intval($match[1]); $width = intval($match[1]);
$height = intval($match[2]); $height = intval($match[2]);
$photo_img->scaleDown(max($width, $height)); $photo_img->scaleDown(max($width, $height));
@ -2824,15 +2824,15 @@ class Item
} }
} }
$new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]'; $new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
$orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]')); $orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]'));
if ($orig_body === false) { if ($orig_body === false) {
$orig_body = ''; $orig_body = '';
} }
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
} }
$new_body = $new_body . $orig_body; $new_body = $new_body . $orig_body;
@ -2937,9 +2937,9 @@ class Item
$expire_items = true; $expire_items = true;
} }
$expire_notes = (bool)DI::pConfig()->get($uid, 'expire', 'notes', true); $expire_notes = (bool)DI::pConfig()->get($uid, 'expire', 'notes', true);
$expire_starred = (bool)DI::pConfig()->get($uid, 'expire', 'starred', true); $expire_starred = (bool)DI::pConfig()->get($uid, 'expire', 'starred', true);
$expire_photos = (bool)DI::pConfig()->get($uid, 'expire', 'photos', false); $expire_photos = (bool)DI::pConfig()->get($uid, 'expire', 'photos', false);
$expired = 0; $expired = 0;
@ -3115,7 +3115,7 @@ class Item
} }
$condition = [ $condition = [
'vid' => $vids, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY, 'vid' => $vids, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
'author-id' => $author_id, 'uid' => $uid, 'thr-parent-id' => $uri_id 'author-id' => $author_id, 'uid' => $uid, 'thr-parent-id' => $uri_id
]; ];
$like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition); $like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition);
@ -3161,29 +3161,29 @@ class Item
$objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE; $objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE;
$new_item = [ $new_item = [
'guid' => System::createUUID(), 'guid' => System::createUUID(),
'uri' => self::newURI(), 'uri' => self::newURI(),
'uid' => $uid, 'uid' => $uid,
'contact-id' => $owner['id'], 'contact-id' => $owner['id'],
'wall' => $item['wall'], 'wall' => $item['wall'],
'origin' => 1, 'origin' => 1,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'protocol' => Conversation::PARCEL_DIRECT, 'protocol' => Conversation::PARCEL_DIRECT,
'direction' => Conversation::PUSH, 'direction' => Conversation::PUSH,
'gravity' => self::GRAVITY_ACTIVITY, 'gravity' => self::GRAVITY_ACTIVITY,
'parent' => $item['id'], 'parent' => $item['id'],
'thr-parent' => $item['uri'], 'thr-parent' => $item['uri'],
'owner-id' => $author_id, 'owner-id' => $author_id,
'author-id' => $author_id, 'author-id' => $author_id,
'body' => $activity, 'body' => $activity,
'verb' => $activity, 'verb' => $activity,
'object-type' => $objtype, 'object-type' => $objtype,
'allow_cid' => $allow_cid ?? $item['allow_cid'], 'allow_cid' => $allow_cid ?? $item['allow_cid'],
'allow_gid' => $allow_gid ?? $item['allow_gid'], 'allow_gid' => $allow_gid ?? $item['allow_gid'],
'deny_cid' => $deny_cid ?? $item['deny_cid'], 'deny_cid' => $deny_cid ?? $item['deny_cid'],
'deny_gid' => $deny_gid ?? $item['deny_gid'], 'deny_gid' => $deny_gid ?? $item['deny_gid'],
'visible' => 1, 'visible' => 1,
'unseen' => 1, 'unseen' => 1,
]; ];
if (in_array($activity, [Activity::LIKE, Activity::DISLIKE])) { if (in_array($activity, [Activity::LIKE, Activity::DISLIKE])) {
@ -3211,7 +3211,7 @@ class Item
*/ */
public static function getPermissionsConditionArrayByUserId(int $owner_id): array public static function getPermissionsConditionArrayByUserId(int $owner_id): array
{ {
$local_user = DI::userSession()->getLocalUserId(); $local_user = DI::userSession()->getLocalUserId();
$remote_user = DI::userSession()->getRemoteContactID($owner_id); $remote_user = DI::userSession()->getRemoteContactID($owner_id);
// default permissions - anonymous user // default permissions - anonymous user
@ -3245,7 +3245,7 @@ class Item
*/ */
public static function getPermissionsSQLByUserId(int $owner_id, string $table = ''): string public static function getPermissionsSQLByUserId(int $owner_id, string $table = ''): string
{ {
$local_user = DI::userSession()->getLocalUserId(); $local_user = DI::userSession()->getLocalUserId();
$remote_user = DI::userSession()->getRemoteContactID($owner_id); $remote_user = DI::userSession()->getRemoteContactID($owner_id);
if (!empty($table)) { if (!empty($table)) {
@ -3373,7 +3373,7 @@ class Item
public static function prepareBody(array &$item, bool $attach = false, bool $is_preview = false, bool $only_cache = false): string public static function prepareBody(array &$item, bool $attach = false, bool $is_preview = false, bool $only_cache = false): string
{ {
$appHelper = DI::appHelper(); $appHelper = DI::appHelper();
$uid = DI::userSession()->getLocalUserId(); $uid = DI::userSession()->getLocalUserId();
Hook::callAll('prepare_body_init', $item); Hook::callAll('prepare_body_init', $item);
// In order to provide theme developers more possibilities, event items // In order to provide theme developers more possibilities, event items
@ -3385,7 +3385,7 @@ class Item
$tags = Tag::populateFromItem($item); $tags = Tag::populateFromItem($item);
$item['tags'] = $tags['tags']; $item['tags'] = $tags['tags'];
$item['hashtags'] = $tags['hashtags']; $item['hashtags'] = $tags['hashtags'];
$item['mentions'] = $tags['mentions']; $item['mentions'] = $tags['mentions'];
@ -3409,12 +3409,12 @@ class Item
$shared = DI::contentItem()->getSharedPost($item, $fields); $shared = DI::contentItem()->getSharedPost($item, $fields);
if (!empty($shared['post'])) { if (!empty($shared['post'])) {
$shared_item = $shared['post']; $shared_item = $shared['post'];
$shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']); $shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
$shared_item['body'] = Post\Media::replaceImage($shared_item['body']); $shared_item['body'] = Post\Media::replaceImage($shared_item['body']);
$quote_uri_id = $shared['post']['uri-id']; $quote_uri_id = $shared['post']['uri-id'];
$shared_links[] = strtolower($shared['post']['uri']); $shared_links[] = strtolower($shared['post']['uri']);
$item['body'] = BBCode::removeSharedData($item['body']); $item['body'] = BBCode::removeSharedData($item['body']);
} elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id']) && ($item['network'] != Protocol::DIASPORA)) { } elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id']) && ($item['network'] != Protocol::DIASPORA)) {
$media = Post\Media::getByURIId($item['uri-id'], [Post\Media::ACTIVITY]); $media = Post\Media::getByURIId($item['uri-id'], [Post\Media::ACTIVITY]);
if (!empty($media) && ($media[0]['media-uri-id'] != $item['uri-id'])) { if (!empty($media) && ($media[0]['media-uri-id'] != $item['uri-id'])) {
@ -3426,7 +3426,7 @@ class Item
} }
if (empty($shared_item['uri-id'])) { if (empty($shared_item['uri-id'])) {
$shared_item = Post::selectFirst($fields, ['uri' => $media[0]['url'], 'uid' => [$item['uid'], 0]]); $shared_item = Post::selectFirst($fields, ['uri' => $media[0]['url'], 'uid' => [$item['uid'], 0]]);
$shared_links[] = strtolower($media[0]['url']); $shared_links[] = strtolower($media[0]['url']);
} }
@ -3452,21 +3452,21 @@ class Item
$sharedSplitAttachments = []; $sharedSplitAttachments = [];
if (!empty($shared_item['uri-id'])) { if (!empty($shared_item['uri-id'])) {
$shared_uri_id = $shared_item['uri-id']; $shared_uri_id = $shared_item['uri-id'];
$shared_links[] = strtolower($shared_item['plink']); $shared_links[] = strtolower($shared_item['plink']);
$sharedSplitAttachments = DI::postMediaRepository()->splitAttachments($shared_uri_id, [], $shared_item['has-media']); $sharedSplitAttachments = DI::postMediaRepository()->splitAttachments($shared_uri_id, [], $shared_item['has-media']);
$shared_links = array_merge($shared_links, $sharedSplitAttachments['visual']->column('url')); $shared_links = array_merge($shared_links, $sharedSplitAttachments['visual']->column('url'));
$shared_links = array_merge($shared_links, $sharedSplitAttachments['link']->column('url')); $shared_links = array_merge($shared_links, $sharedSplitAttachments['link']->column('url'));
$shared_links = array_merge($shared_links, $sharedSplitAttachments['additional']->column('url')); $shared_links = array_merge($shared_links, $sharedSplitAttachments['additional']->column('url'));
$item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body']); $item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body']);
} }
$itemSplitAttachments = DI::postMediaRepository()->splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false); $itemSplitAttachments = DI::postMediaRepository()->splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
$item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? ''); $item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? '');
self::putInCache($item); self::putInCache($item);
$item['body'] = $body; $item['body'] = $body;
$s = $item["rendered-html"]; $s = $item["rendered-html"];
if ($only_cache) { if ($only_cache) {
return ''; return '';
@ -3490,7 +3490,7 @@ class Item
$item['attachments'] = $itemSplitAttachments; $item['attachments'] = $itemSplitAttachments;
$hook_data = [ $hook_data = [
'item' => $item, 'item' => $item,
'filter_reasons' => $filter_reasons 'filter_reasons' => $filter_reasons
]; ];
Hook::callAll('prepare_body_content_filter', $hook_data); Hook::callAll('prepare_body_content_filter', $hook_data);
@ -3503,9 +3503,9 @@ class Item
} }
$hook_data = [ $hook_data = [
'item' => $item, 'item' => $item,
'html' => $s, 'html' => $s,
'preview' => $is_preview, 'preview' => $is_preview,
'filter_reasons' => $filter_reasons 'filter_reasons' => $filter_reasons
]; ];
Hook::callAll('prepare_body', $hook_data); Hook::callAll('prepare_body', $hook_data);
@ -3516,22 +3516,22 @@ class Item
if (!$attach) { if (!$attach) {
// Replace the blockquotes with quotes that are used in mails. // Replace the blockquotes with quotes that are used in mails.
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">'; $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s); $s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
return $s; return $s;
} }
if (!empty($sharedSplitAttachments)) { if (!empty($sharedSplitAttachments)) {
$s = self::addGallery($s, $sharedSplitAttachments['visual']); $s = self::addGallery($s, $sharedSplitAttachments['visual']);
$s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true); $s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true);
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links); $s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links);
$s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s); $s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s);
$body = BBCode::removeSharedData($body); $body = BBCode::removeSharedData($body);
} }
$pos = strpos($s, BBCode::SHARED_ANCHOR); $pos = strpos($s, BBCode::SHARED_ANCHOR);
if ($pos) { if ($pos) {
$shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR)); $shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR));
$s = substr($s, 0, $pos); $s = substr($s, 0, $pos);
} }
$s = self::addGallery($s, $itemSplitAttachments['visual']); $s = self::addGallery($s, $itemSplitAttachments['visual']);
@ -3551,7 +3551,7 @@ class Item
// Replace friendica image url size with theme preference. // Replace friendica image url size with theme preference.
if (!empty($appHelper->getThemeInfoValue('item_image_size'))) { if (!empty($appHelper->getThemeInfoValue('item_image_size'))) {
$ps = $appHelper->getThemeInfoValue('item_image_size'); $ps = $appHelper->getThemeInfoValue('item_image_size');
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s); $s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
} }
if (!empty($shared_html)) { if (!empty($shared_html)) {
@ -3593,7 +3593,7 @@ class Item
continue; continue;
} }
$element_html = $element->ownerDocument->saveHTML($element); $element_html = $element->ownerDocument->saveHTML($element);
$html = str_replace($element_html, str_replace($src, $svg, $element_html), $html); $html = str_replace($element_html, str_replace($src, $svg, $element_html), $html);
} }
return $html; return $html;
} }
@ -3617,8 +3617,8 @@ class Item
$s = preg_replace_callback($pattern, function () use ($PostMedia) { $s = preg_replace_callback($pattern, function () use ($PostMedia) {
return Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image/single_with_height_allocation.tpl'), [ return Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image/single_with_height_allocation.tpl'), [
'$image' => $PostMedia, '$image' => $PostMedia,
'$allocated_height' => $PostMedia->getAllocatedHeight(), '$allocated_height' => $PostMedia->getAllocatedHeight(),
'$allocated_max_width' => ($PostMedia->previewWidth ?? $PostMedia->width) . 'px', '$allocated_max_width' => ($PostMedia->previewWidth ?? $PostMedia->width) . 'px',
]); ]);
}, $s); }, $s);
@ -3742,10 +3742,10 @@ class Item
if ($PostMedia->mimetype->type == 'image' || $PostMedia->preview) { if ($PostMedia->mimetype->type == 'image' || $PostMedia->preview) {
$preview_size = Proxy::SIZE_MEDIUM; $preview_size = Proxy::SIZE_MEDIUM;
$preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size); $preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
} else { } else {
$preview_size = 0; $preview_size = 0;
$preview_url = ''; $preview_url = '';
} }
if ($preview_url && self::containsLink($item['body'], $preview_url)) { if ($preview_url && self::containsLink($item['body'], $preview_url)) {
@ -3781,10 +3781,10 @@ class Item
} elseif ($PostMedia->mimetype->type == 'audio') { } elseif ($PostMedia->mimetype->type == 'audio') {
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [ $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
'$audio' => [ '$audio' => [
'id' => $PostMedia->id, 'id' => $PostMedia->id,
'src' => (string)$PostMedia->url, 'src' => (string)$PostMedia->url,
'name' => $PostMedia->name ?: $PostMedia->url, 'name' => $PostMedia->name ?: $PostMedia->url,
'mime' => (string)$PostMedia->mimetype, 'mime' => (string)$PostMedia->mimetype,
], ],
]); ]);
if (($item['post-type'] ?? null) == Item::PT_AUDIO) { if (($item['post-type'] ?? null) == Item::PT_AUDIO) {
@ -3848,7 +3848,7 @@ class Item
{ {
DI::profiler()->startRecording('rendering'); DI::profiler()->startRecording('rendering');
// Don't show a preview when there is a visual attachment (audio or video) // Don't show a preview when there is a visual attachment (audio or video)
$types = $attachments['visual']->column('type'); $types = $attachments['visual']->column('type');
$preview = !in_array(PostMedia::TYPE_IMAGE, $types) && !in_array(PostMedia::TYPE_VIDEO, $types); $preview = !in_array(PostMedia::TYPE_IMAGE, $types) && !in_array(PostMedia::TYPE_VIDEO, $types);
/** @var ?PostMedia $attachment */ /** @var ?PostMedia $attachment */
@ -3871,18 +3871,18 @@ class Item
if (!empty($attachment)) { if (!empty($attachment)) {
$data = [ $data = [
'after' => '', 'after' => '',
'author_name' => $attachment->authorName ?? '', 'author_name' => $attachment->authorName ?? '',
'author_url' => (string)($attachment->authorUrl ?? ''), 'author_url' => (string)($attachment->authorUrl ?? ''),
'description' => $attachment->description ?? '', 'description' => $attachment->description ?? '',
'image' => '', 'image' => '',
'preview' => '', 'preview' => '',
'provider_name' => $attachment->publisherName ?? '', 'provider_name' => $attachment->publisherName ?? '',
'provider_url' => (string)($attachment->publisherUrl ?? ''), 'provider_url' => (string)($attachment->publisherUrl ?? ''),
'text' => '', 'text' => '',
'title' => $attachment->name ?? '', 'title' => $attachment->name ?? '',
'type' => 'link', 'type' => 'link',
'url' => (string)$attachment->url, 'url' => (string)$attachment->url,
]; ];
if ($preview && $attachment->preview) { if ($preview && $attachment->preview) {
@ -4023,7 +4023,7 @@ class Item
$options = Post\QuestionOption::getByURIId($item['uri-id']); $options = Post\QuestionOption::getByURIId($item['uri-id']);
foreach ($options as $key => $option) { foreach ($options as $key => $option) {
if ($question['voters'] > 0) { if ($question['voters'] > 0) {
$percent = $option['replies'] / $question['voters'] * 100; $percent = $option['replies'] / $question['voters'] * 100;
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'] ?? 0, $option['name'], round($percent, 1)); $options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'] ?? 0, $option['name'], round($percent, 1));
} else { } else {
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'] ?? 0, $option['name']); $options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'] ?? 0, $option['name']);
@ -4074,9 +4074,9 @@ class Item
if (DI::userSession()->getLocalUserId()) { if (DI::userSession()->getLocalUserId()) {
$ret = [ $ret = [
'href' => "display/" . $item['guid'], 'href' => "display/" . $item['guid'],
'orig' => "display/" . $item['guid'], 'orig' => "display/" . $item['guid'],
'title' => DI::l10n()->t('View on separate page'), 'title' => DI::l10n()->t('View on separate page'),
'orig_title' => DI::l10n()->t('View on separate page'), 'orig_title' => DI::l10n()->t('View on separate page'),
]; ];
@ -4092,14 +4092,14 @@ class Item
} }
if (!empty($plink)) { if (!empty($plink)) {
$ret['href'] = DI::baseUrl()->remove($plink); $ret['href'] = DI::baseUrl()->remove($plink);
$ret['title'] = DI::l10n()->t('Link to source'); $ret['title'] = DI::l10n()->t('Link to source');
} }
} elseif (!empty($plink) && ($item['private'] != self::PRIVATE)) { } elseif (!empty($plink) && ($item['private'] != self::PRIVATE)) {
$ret = [ $ret = [
'href' => $plink, 'href' => $plink,
'orig' => $plink, 'orig' => $plink,
'title' => DI::l10n()->t('Link to source'), 'title' => DI::l10n()->t('Link to source'),
'orig_title' => DI::l10n()->t('Link to source'), 'orig_title' => DI::l10n()->t('Link to source'),
]; ];
} else { } else {
@ -4144,7 +4144,7 @@ class Item
public static function searchByLink(string $uri, int $uid = 0): int public static function searchByLink(string $uri, int $uid = 0): int
{ {
$ssl_uri = str_replace('http://', 'https://', $uri); $ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)]; $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
$item = Post::selectFirst(['id'], ['uri' => $uris, 'uid' => $uid]); $item = Post::selectFirst(['id'], ['uri' => $uris, 'uid' => $uid]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
@ -4169,7 +4169,7 @@ class Item
public static function getURIByLink(string $uri): string public static function getURIByLink(string $uri): string
{ {
$ssl_uri = str_replace('http://', 'https://', $uri); $ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)]; $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
$item = Post::selectFirst(['uri'], ['uri' => $uris]); $item = Post::selectFirst(['uri'], ['uri' => $uris]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
@ -4223,7 +4223,7 @@ class Item
if (!$mimetype) { if (!$mimetype) {
try { try {
$curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS, HttpClientOptions::REQUEST => HttpClientRequest::ACTIVITYPUB]); $curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS, HttpClientOptions::REQUEST => HttpClientRequest::ACTIVITYPUB]);
$mimetype = $curlResult->getContentType(); $mimetype = $curlResult->getContentType();
} catch (\Throwable $th) { } catch (\Throwable $th) {
Logger::info('Error while fetching HTTP link via HEAD', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]); Logger::info('Error while fetching HTTP link via HEAD', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
return 0; return 0;
@ -4234,7 +4234,7 @@ class Item
try { try {
// Issue 14126: Workaround for Mastodon servers that return "application/json" on a "head" request. // Issue 14126: Workaround for Mastodon servers that return "application/json" on a "head" request.
$curlResult = HTTPSignature::fetchRaw($uri, $uid); $curlResult = HTTPSignature::fetchRaw($uri, $uid);
$mimetype = $curlResult->getContentType(); $mimetype = $curlResult->getContentType();
} catch (\Throwable $th) { } catch (\Throwable $th) {
Logger::info('Error while fetching HTTP link via signed GET', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]); Logger::info('Error while fetching HTTP link via signed GET', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
return 0; return 0;
@ -4265,7 +4265,7 @@ class Item
/** /**
* Fetch the uri-id of a quoted post by searching for data in the body or attached media * Fetch the uri-id of a quoted post by searching for data in the body or attached media
* *
* @param string $body The body of the * @param string $body The body of the
* @param int $uid The id of the user * @param int $uid The id of the user
* @return integer * @return integer
*/ */
@ -4306,7 +4306,7 @@ class Item
} }
$url = $shared['message_id'] ?: $shared['link']; $url = $shared['message_id'] ?: $shared['link'];
$id = self::fetchByLink($url, 0, ActivityPub\Receiver::COMPLETION_ASYNC); $id = self::fetchByLink($url, 0, ActivityPub\Receiver::COMPLETION_ASYNC);
if (!$id) { if (!$id) {
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]); Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]);
return 0; return 0;

View file

@ -90,8 +90,8 @@ class Media
} }
$media['url'] = Network::sanitizeUrl($media['url']); $media['url'] = Network::sanitizeUrl($media['url']);
$media = self::unsetEmptyFields($media); $media = self::unsetEmptyFields($media);
$media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media); $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
// We are storing as fast as possible to avoid duplicated network requests // We are storing as fast as possible to avoid duplicated network requests
// when fetching additional information for pictures and other content. // when fetching additional information for pictures and other content.
@ -218,9 +218,9 @@ class Media
$imagedata = Images::getInfoFromURLCached($media['url'], empty($media['description'])); $imagedata = Images::getInfoFromURLCached($media['url'], empty($media['description']));
if ($imagedata) { if ($imagedata) {
$media['mimetype'] = $imagedata['mime']; $media['mimetype'] = $imagedata['mime'];
$media['size'] = $imagedata['size']; $media['size'] = $imagedata['size'];
$media['width'] = $imagedata[0]; $media['width'] = $imagedata[0];
$media['height'] = $imagedata[1]; $media['height'] = $imagedata[1];
$media['blurhash'] = $imagedata['blurhash'] ?? null; $media['blurhash'] = $imagedata['blurhash'] ?? null;
if (!empty($imagedata['description']) && empty($media['description'])) { if (!empty($imagedata['description']) && empty($media['description'])) {
$media['description'] = $imagedata['description']; $media['description'] = $imagedata['description'];
@ -276,13 +276,13 @@ class Media
// When the original picture is potentially animated but the preview isn't, we override the preview // When the original picture is potentially animated but the preview isn't, we override the preview
if (in_array($media['mimetype'] ?? '', ['image/gif', 'image/png']) && !in_array($imagedata['mime'], ['image/gif', 'image/png'])) { if (in_array($media['mimetype'] ?? '', ['image/gif', 'image/png']) && !in_array($imagedata['mime'], ['image/gif', 'image/png'])) {
$media['preview'] = $media['url']; $media['preview'] = $media['url'];
$media['preview-width'] = $media['width']; $media['preview-width'] = $media['width'];
$media['preview-height'] = $media['height']; $media['preview-height'] = $media['height'];
return $media; return $media;
} }
$media['preview-width'] = $imagedata[0]; $media['preview-width'] = $imagedata[0];
$media['preview-height'] = $imagedata[1]; $media['preview-height'] = $imagedata[1];
} }
@ -336,21 +336,21 @@ class Media
$gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]); $gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]);
} }
$media['type'] = self::ACTIVITY; $media['type'] = self::ACTIVITY;
$media['media-uri-id'] = $item['uri-id']; $media['media-uri-id'] = $item['uri-id'];
$media['height'] = null; $media['height'] = null;
$media['width'] = null; $media['width'] = null;
$media['preview'] = null; $media['preview'] = null;
$media['preview-height'] = null; $media['preview-height'] = null;
$media['preview-width'] = null; $media['preview-width'] = null;
$media['blurhash'] = null; $media['blurhash'] = null;
$media['description'] = $item['body']; $media['description'] = $item['body'];
$media['name'] = $item['title']; $media['name'] = $item['title'];
$media['author-url'] = $item['author-link']; $media['author-url'] = $item['author-link'];
$media['author-name'] = $item['author-name']; $media['author-name'] = $item['author-name'];
$media['author-image'] = $contact['avatar'] ?? $item['author-avatar']; $media['author-image'] = $contact['avatar'] ?? $item['author-avatar'];
$media['publisher-url'] = $gserver['url'] ?? null; $media['publisher-url'] = $gserver['url'] ?? null;
$media['publisher-name'] = $gserver['site_name'] ?? null; $media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null; $media['publisher-image'] = null;
Logger::debug('Activity detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'plink' => $item['plink'], 'uri' => $item['uri']]); Logger::debug('Activity detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'plink' => $item['plink'], 'uri' => $item['uri']]);
@ -378,21 +378,21 @@ class Media
$gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]); $gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]);
} }
$media['type'] = self::ACCOUNT; $media['type'] = self::ACCOUNT;
$media['media-uri-id'] = $contact['uri-id']; $media['media-uri-id'] = $contact['uri-id'];
$media['height'] = null; $media['height'] = null;
$media['width'] = null; $media['width'] = null;
$media['preview'] = null; $media['preview'] = null;
$media['preview-height'] = null; $media['preview-height'] = null;
$media['preview-width'] = null; $media['preview-width'] = null;
$media['blurhash'] = null; $media['blurhash'] = null;
$media['description'] = $contact['about']; $media['description'] = $contact['about'];
$media['name'] = $contact['name']; $media['name'] = $contact['name'];
$media['author-url'] = $contact['url']; $media['author-url'] = $contact['url'];
$media['author-name'] = $contact['name']; $media['author-name'] = $contact['name'];
$media['author-image'] = $contact['avatar']; $media['author-image'] = $contact['avatar'];
$media['publisher-url'] = $gserver['url'] ?? null; $media['publisher-url'] = $gserver['url'] ?? null;
$media['publisher-name'] = $gserver['site_name'] ?? null; $media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null; $media['publisher-image'] = null;
Logger::debug('Account detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'uri' => $contact['url']]); Logger::debug('Account detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'uri' => $contact['url']]);
@ -414,21 +414,21 @@ class Media
Logger::debug('Detected site data is empty, use suggested media data instead', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'type' => $data['type']]); Logger::debug('Detected site data is empty, use suggested media data instead', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'type' => $data['type']]);
} }
} else { } else {
$media['preview'] = $data['images'][0]['src'] ?? null; $media['preview'] = $data['images'][0]['src'] ?? null;
$media['preview-height'] = $data['images'][0]['height'] ?? null; $media['preview-height'] = $data['images'][0]['height'] ?? null;
$media['preview-width'] = $data['images'][0]['width'] ?? null; $media['preview-width'] = $data['images'][0]['width'] ?? null;
$media['blurhash'] = $data['images'][0]['blurhash'] ?? null; $media['blurhash'] = $data['images'][0]['blurhash'] ?? null;
$media['description'] = $data['text'] ?? null; $media['description'] = $data['text'] ?? null;
$media['name'] = $data['title'] ?? null; $media['name'] = $data['title'] ?? null;
} }
$media['type'] = self::HTML; $media['type'] = self::HTML;
$media['size'] = $data['size'] ?? null; $media['size'] = $data['size'] ?? null;
$media['author-url'] = $data['author_url'] ?? null; $media['author-url'] = $data['author_url'] ?? null;
$media['author-name'] = $data['author_name'] ?? null; $media['author-name'] = $data['author_name'] ?? null;
$media['author-image'] = $data['author_img'] ?? null; $media['author-image'] = $data['author_img'] ?? null;
$media['publisher-url'] = $data['publisher_url'] ?? null; $media['publisher-url'] = $data['publisher_url'] ?? null;
$media['publisher-name'] = $data['publisher_name'] ?? null; $media['publisher-name'] = $data['publisher_name'] ?? null;
$media['publisher-image'] = $data['publisher_img'] ?? null; $media['publisher-image'] = $data['publisher_img'] ?? null;
return $media; return $media;
@ -458,9 +458,9 @@ class Media
$photo = Photo::selectFirst(['type', 'datasize', 'width', 'height', 'blurhash'], ['resource-id' => $matches[1], 'scale' => $matches[2]]); $photo = Photo::selectFirst(['type', 'datasize', 'width', 'height', 'blurhash'], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
if (!empty($photo)) { if (!empty($photo)) {
$media['mimetype'] = $photo['type']; $media['mimetype'] = $photo['type'];
$media['size'] = $photo['datasize']; $media['size'] = $photo['datasize'];
$media['width'] = $photo['width']; $media['width'] = $photo['width'];
$media['height'] = $photo['height']; $media['height'] = $photo['height'];
$media['blurhash'] = $photo['blurhash']; $media['blurhash'] = $photo['blurhash'];
} }
@ -469,7 +469,7 @@ class Media
} }
$photo = Photo::selectFirst(['width', 'height'], ['resource-id' => $matches[1], 'scale' => $matches[2]]); $photo = Photo::selectFirst(['width', 'height'], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
if (!empty($photo)) { if (!empty($photo)) {
$media['preview-width'] = $photo['width']; $media['preview-width'] = $photo['width'];
$media['preview-height'] = $photo['height']; $media['preview-height'] = $photo['height'];
} }
@ -502,7 +502,7 @@ class Media
} }
$filetype = strtolower($type[0]); $filetype = strtolower($type[0]);
$subtype = strtolower($type[1]); $subtype = strtolower($type[1]);
if ($filetype == 'image') { if ($filetype == 'image') {
$type = self::IMAGE; $type = self::IMAGE;
@ -609,22 +609,22 @@ class Media
if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) { if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) { foreach ($pictures as $picture) {
if (self::isLinkToImagePage($picture[1], $picture[2])) { if (self::isLinkToImagePage($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$image = str_replace(['-1.', '-2.'], '-0.', $picture[2]); $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
$attachments[$image] = [ $attachments[$image] = [
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
'preview' => $picture[2], 'description' => $picture[3] 'preview' => $picture[2], 'description' => $picture[3]
]; ];
} elseif (self::isLinkToPhoto($picture[1], $picture[2])) { } elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = [ $attachments[$picture[1]] = [
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1], 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1],
'preview' => $picture[2], 'description' => $picture[3] 'preview' => $picture[2], 'description' => $picture[3]
]; ];
} elseif ($removepicturelinks) { } elseif ($removepicturelinks) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = [ $attachments[$picture[1]] = [
'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1], 'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1],
'preview' => $picture[2], 'description' => $picture[3] 'preview' => $picture[2], 'description' => $picture[3]
]; ];
} }
@ -633,7 +633,7 @@ class Media
if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]$endmatchpattern/Usi", $body, $pictures, PREG_SET_ORDER)) { if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]$endmatchpattern/Usi", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) { foreach ($pictures as $picture) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1], 'description' => $picture[2]]; $attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1], 'description' => $picture[2]];
} }
} }
@ -641,22 +641,22 @@ class Media
if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) { if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) { foreach ($pictures as $picture) {
if (self::isLinkToImagePage($picture[1], $picture[2])) { if (self::isLinkToImagePage($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$image = str_replace(['-1.', '-2.'], '-0.', $picture[2]); $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
$attachments[$image] = [ $attachments[$image] = [
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
'preview' => $picture[2], 'description' => null 'preview' => $picture[2], 'description' => null
]; ];
} elseif (self::isLinkToPhoto($picture[1], $picture[2])) { } elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = [ $attachments[$picture[1]] = [
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1], 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1],
'preview' => $picture[2], 'description' => null 'preview' => $picture[2], 'description' => null
]; ];
} elseif ($removepicturelinks) { } elseif ($removepicturelinks) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = [ $attachments[$picture[1]] = [
'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1], 'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1],
'preview' => $picture[2], 'description' => null 'preview' => $picture[2], 'description' => null
]; ];
} }
@ -665,21 +665,21 @@ class Media
if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]$endmatchpattern/ism", $body, $pictures, PREG_SET_ORDER)) { if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]$endmatchpattern/ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) { foreach ($pictures as $picture) {
$body = str_replace($picture[0], '', $body); $body = str_replace($picture[0], '', $body);
$attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1]]; $attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1]];
} }
} }
if (preg_match_all("/\[audio\]([^\[\]]*)\[\/audio\]$endmatchpattern/ism", $body, $audios, PREG_SET_ORDER)) { if (preg_match_all("/\[audio\]([^\[\]]*)\[\/audio\]$endmatchpattern/ism", $body, $audios, PREG_SET_ORDER)) {
foreach ($audios as $audio) { foreach ($audios as $audio) {
$body = str_replace($audio[0], '', $body); $body = str_replace($audio[0], '', $body);
$attachments[$audio[1]] = ['uri-id' => $uriid, 'type' => self::AUDIO, 'url' => $audio[1]]; $attachments[$audio[1]] = ['uri-id' => $uriid, 'type' => self::AUDIO, 'url' => $audio[1]];
} }
} }
if (preg_match_all("/\[video\]([^\[\]]*)\[\/video\]$endmatchpattern/ism", $body, $videos, PREG_SET_ORDER)) { if (preg_match_all("/\[video\]([^\[\]]*)\[\/video\]$endmatchpattern/ism", $body, $videos, PREG_SET_ORDER)) {
foreach ($videos as $video) { foreach ($videos as $video) {
$body = str_replace($video[0], '', $body); $body = str_replace($video[0], '', $body);
$attachments[$video[1]] = ['uri-id' => $uriid, 'type' => self::VIDEO, 'url' => $video[1]]; $attachments[$video[1]] = ['uri-id' => $uriid, 'type' => self::VIDEO, 'url' => $video[1]];
} }
} }
@ -710,7 +710,7 @@ class Media
{ {
do { do {
$prebody = $body; $prebody = $body;
$body = self::insertFromBody(0, $body, true); $body = self::insertFromBody(0, $body, true);
} while ($prebody != $body); } while ($prebody != $body);
return $body; return $body;
} }
@ -725,7 +725,7 @@ class Media
{ {
do { do {
$prebody = $body; $prebody = $body;
$body = self::insertFromBody(0, $body, false, true); $body = self::insertFromBody(0, $body, false, true);
} while ($prebody != $body); } while ($prebody != $body);
return $body; return $body;
} }
@ -808,15 +808,15 @@ class Media
Logger::info('Adding attachment data', ['data' => $data]); Logger::info('Adding attachment data', ['data' => $data]);
$attachment = [ $attachment = [
'uri-id' => $uriid, 'uri-id' => $uriid,
'type' => self::HTML, 'type' => self::HTML,
'url' => $data['url'], 'url' => $data['url'],
'preview' => $data['preview'] ?? null, 'preview' => $data['preview'] ?? null,
'description' => $data['description'] ?? null, 'description' => $data['description'] ?? null,
'name' => $data['title'] ?? null, 'name' => $data['title'] ?? null,
'author-url' => $data['author_url'] ?? null, 'author-url' => $data['author_url'] ?? null,
'author-name' => $data['author_name'] ?? null, 'author-name' => $data['author_name'] ?? null,
'publisher-url' => $data['provider_url'] ?? null, 'publisher-url' => $data['provider_url'] ?? null,
'publisher-name' => $data['provider_name'] ?? null, 'publisher-name' => $data['provider_name'] ?? null,
]; ];
if (!empty($data['image'])) { if (!empty($data['image'])) {
@ -839,11 +839,11 @@ class Media
} }
foreach ($matches as $attachment) { foreach ($matches as $attachment) {
$media['type'] = self::DOCUMENT; $media['type'] = self::DOCUMENT;
$media['uri-id'] = $uriid; $media['uri-id'] = $uriid;
$media['url'] = $attachment[1]; $media['url'] = $attachment[1];
$media['size'] = $attachment[2]; $media['size'] = $attachment[2];
$media['mimetype'] = $attachment[3]; $media['mimetype'] = $attachment[3];
$media['description'] = $attachment[4] ?? ''; $media['description'] = $attachment[4] ?? '';
self::insert($media); self::insert($media);
@ -1036,20 +1036,20 @@ class Media
} }
$data = [ $data = [
'type' => 'link', 'type' => 'link',
'url' => $links[0]['url'], 'url' => $links[0]['url'],
'title' => $links[0]['name'], 'title' => $links[0]['name'],
'text' => $links[0]['description'], 'text' => $links[0]['description'],
'publisher_name' => $links[0]['publisher-name'], 'publisher_name' => $links[0]['publisher-name'],
'publisher_url' => $links[0]['publisher-url'], 'publisher_url' => $links[0]['publisher-url'],
'publisher_img' => $links[0]['publisher-image'], 'publisher_img' => $links[0]['publisher-image'],
'author_name' => $links[0]['author-name'], 'author_name' => $links[0]['author-name'],
'author_url' => $links[0]['author-url'], 'author_url' => $links[0]['author-url'],
'author_img' => $links[0]['author-image'], 'author_img' => $links[0]['author-image'],
'images' => [[ 'images' => [[
'src' => $links[0]['preview'], 'src' => $links[0]['preview'],
'height' => $links[0]['preview-height'], 'height' => $links[0]['preview-height'],
'width' => $links[0]['preview-width'], 'width' => $links[0]['preview-width'],
]] ]]
]; ];
$body .= "\n" . PageInfo::getFooterFromData($data); $body .= "\n" . PageInfo::getFooterFromData($data);

View file

@ -9,9 +9,6 @@ declare(strict_types=1);
namespace Friendica\Service\Addon; namespace Friendica\Service\Addon;
use Friendica\Addon\AddonBootstrap;
use Psr\Log\LoggerInterface;
/** /**
* Manager for all addons. * Manager for all addons.
*/ */

View file

@ -14,7 +14,6 @@ use Friendica\Service\Addon\Addon;
use Friendica\Service\Addon\AddonLoader; use Friendica\Service\Addon\AddonLoader;
use Friendica\Service\Addon\AddonManager; use Friendica\Service\Addon\AddonManager;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class AddonManagerTest extends TestCase class AddonManagerTest extends TestCase
{ {