<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\DI;
use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Delivery;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
-use Friendica\Worker\Delivery;
use GuzzleHttp\Psr7\Uri;
use LanguageDetection\Language;
private static function prepareOriginPost(array $item): array
{
- $item['wall'] = 1;
- $item['origin'] = 1;
- $item['network'] = Protocol::DFRN;
- $item['protocol'] = Conversation::PARCEL_DIRECT;
- $item['direction'] = Conversation::PUSH;
+ $item = DI::contentItem()->initializePost($item);
- $owner = User::getOwnerDataById($item['uid']);
-
- if (empty($item['contact-id'])) {
- $item['contact-id'] = $owner['id'];
- }
-
- if (empty($item['author-link']) && empty($item['author-id'])) {
- $item['author-link'] = $owner['url'];
- $item['author-name'] = $owner['name'];
- $item['author-avatar'] = $owner['thumb'];
+ if (Photo::setPermissionFromBody($item['body'], $item['uid'], $item['contact-id'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid'])) {
+ $item['object-type'] = Activity\ObjectType::IMAGE;
}
- if (empty($item['owner-link']) && empty($item['owner-id'])) {
- $item['owner-link'] = $item['author-link'];
- $item['owner-name'] = $item['author-name'];
- $item['owner-avatar'] = $item['author-avatar'];
- }
-
- // Setting the object type if not defined before
- if (empty($item['object-type'])) {
- $item['object-type'] = Activity\ObjectType::NOTE; // Default value
- $objectdata = BBCode::getAttachedData($item['body']);
-
- if ($objectdata['type'] == 'link') {
- $item['object-type'] = Activity\ObjectType::BOOKMARK;
- } elseif ($objectdata['type'] == 'video') {
- $item['object-type'] = Activity\ObjectType::VIDEO;
- } elseif ($objectdata['type'] == 'photo') {
- $item['object-type'] = Activity\ObjectType::IMAGE;
- }
- }
+ $item = DI::contentItem()->moveAttachmentsFromBodyToAttach($item);
+ $item = DI::contentItem()->finalizePost($item);
return $item;
}
}
if ($notify) {
- if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == self::GRAVITY_COMMENT)) {
- Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
- }
- Hook::callAll('post_local_end', $posted_item);
+ DI::contentItem()->postProcessPost($posted_item);
} else {
Hook::callAll('post_remote_end', $posted_item);
}
$item['mentions'] = $tags['mentions'];
if (!$is_preview) {
+ $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
$item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
}
$body = $item['body'];
+ if ($is_preview) {
+ $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
+ }
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
$shared = DI::contentItem()->getSharedPost($item, $fields);
if (!empty($shared['post'])) {
$shared_item = $shared['post'];
+ $shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
$quote_uri_id = $shared['post']['uri-id'];
$shared_links[] = strtolower($shared['post']['uri']);
$item['body'] = BBCode::removeSharedData($item['body']);
$attachments = Post\Media::splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
$item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? '');
- $item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']);
-
self::putInCache($item);
$item['body'] = $body;
$s = $item["rendered-html"];
],
]);
}
-
+
/**
* Check if the body contains a link
}
// @todo Use a template
- $preview_mode = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE);
+ $preview_mode = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE);
if ($preview_mode != BBCode::PREVIEW_NONE) {
$rendered = BBCode::convertAttachment('', BBCode::INTERNAL, false, $data, $uriid, $preview_mode);
+ } else {
+ $rendered = '';
}
} elseif (!self::containsLink($content, $data['url'], Post\Media::HTML)) {
$rendered = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/link.tpl'), [
- '$url' => $data['url'],
+ '$url' => $data['url'],
'$title' => $data['title'],
]);
} else {