use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\BBCode\Video;
use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\BBCode\Video;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\FileTag;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\FileTag;
use Friendica\Protocol\Activity;
use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Protocol\Activity;
use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\ParseUrl;
use Friendica\Util\Profiler;
use Friendica\Util\Proxy;
use Friendica\Util\XML;
use Friendica\Util\ParseUrl;
use Friendica\Util\Profiler;
use Friendica\Util\Proxy;
use Friendica\Util\XML;
- public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL)
+ public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, App $app)
$this->aclFormatter = $aclFormatter;
$this->baseURL = $baseURL;
$this->pConfig = $pConfig;
$this->aclFormatter = $aclFormatter;
$this->baseURL = $baseURL;
$this->pConfig = $pConfig;
- * [ // categories array
- * {
- * 'name': 'category name',
- * 'removeurl': 'url to remove this category',
- * 'first': 'is the first in this array? true/false',
- * 'last': 'is the last in this array? true/false',
- * } ,
- * ....
- * ],
- * [ //folders array
- * {
- * 'name': 'folder name',
- * 'removeurl': 'url to remove this folder',
- * 'first': 'is the first in this array? true/false',
- * 'last': 'is the last in this array? true/false',
- * } ,
- * ....
- * ]
- * ]
+ * [ // categories array
+ * {
+ * 'name': 'category name',
+ * 'removeurl': 'url to remove this category',
+ * 'first': 'is the first in this array? true/false',
+ * 'last': 'is the last in this array? true/false',
+ * },
+ * ...
+ * ],
+ * [ //folders array
+ * {
+ * 'name': 'folder name',
+ * 'removeurl': 'url to remove this folder',
+ * 'first': 'is the first in this array? true/false',
+ * 'last': 'is the last in this array? true/false',
+ * } ,
+ * ...
+ * ]
+ * ]
+ *
+ * @throws \Exception
- $condition = ["`nick` = ? AND `network` = ? AND `uid` = ?",
- $name, $network, $profile_uid];
+ $condition = ['nick' => $name, 'network' => $network, 'uid' => $profile_uid];
$contact = DBA::selectFirst('contact', $fields, $condition);
}
// select someone by attag in the current network
if (!DBA::isResult($contact) && ($network != '')) {
$contact = DBA::selectFirst('contact', $fields, $condition);
}
// select someone by attag in the current network
if (!DBA::isResult($contact) && ($network != '')) {
- $condition = ["`attag` = ? AND `network` = ? AND `uid` = ?",
- $name, $network, $profile_uid];
+ $condition = ['attag' => $name, 'network' => $network, 'uid' => $profile_uid];
$contact = DBA::selectFirst('contact', $fields, $condition);
}
// select someone by attag in any network
if (!DBA::isResult($contact)) {
$contact = DBA::selectFirst('contact', $fields, $condition);
}
// select someone by attag in any network
if (!DBA::isResult($contact)) {
$replaced = true;
// create profile link
$profile = str_replace(',', '%2c', $profile);
$replaced = true;
// create profile link
$profile = str_replace(',', '%2c', $profile);
$xmlhead = '<?xml version="1.0" encoding="UTF-8" ?>';
if ($this->activity->match($item['verb'], Activity::TAG)) {
$xmlhead = '<?xml version="1.0" encoding="UTF-8" ?>';
if ($this->activity->match($item['verb'], Activity::TAG)) {
- $fields = ['author-id', 'author-link', 'author-name', 'author-network',
- 'verb', 'object-type', 'resource-id', 'body', 'plink'];
+ $fields = [
+ 'author-id', 'author-link', 'author-name', 'author-network',
+ 'verb', 'object-type', 'resource-id', 'body', 'plink'
+ ];
$obj = Post::selectFirst($fields, ['uri' => $item['parent-uri']]);
if (!DBA::isResult($obj)) {
$this->profiler->stopRecording();
$obj = Post::selectFirst($fields, ['uri' => $item['parent-uri']]);
if (!DBA::isResult($obj)) {
$this->profiler->stopRecording();
- $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
- $rr['plink'] = $m[1];
+ preg_match("/\[url=([^]]*)\]/", $obj['body'], $matches);
+ $rr['plink'] = $matches[1];
{
$this->profiler->startRecording('rendering');
$sub_link = $contact_url = $pm_url = $status_link = '';
{
$this->profiler->startRecording('rendering');
$sub_link = $contact_url = $pm_url = $status_link = '';
if ($this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
$author = [
if ($this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
$author = [
- $sparkle = (strpos($profile_link, 'contact/redir/') === 0);
+ if (strpos($profile_link, 'contact/redir/') === 0) {
+ $status_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/status']);
+ $photos_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/photos']);
+ $profile_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/profile']);
+ }
- if ($sparkle) {
- $status_link = $profile_link . '/status';
- $photos_link = $profile_link . '/photos';
- $profile_link = $profile_link . '/profile';
+ if (!empty($pcid)) {
+ $contact_url = 'contact/' . $pcid;
+ $posts_link = $contact_url . '/posts';
+ $block_link = $item['self'] ? '' : $contact_url . '/block?t=' . $formSecurityToken;
+ $ignore_link = $item['self'] ? '' : $contact_url . '/ignore?t=' . $formSecurityToken;
+ $collapse_link = $item['self'] ? '' : $contact_url . '/collapse?t=' . $formSecurityToken;
- if (!empty($pcid)) {
- $contact_url = 'contact/' . $pcid;
- $posts_link = $contact_url . '/posts';
- $block_link = $item['self'] ? '' : $contact_url . '/block?t=' . $formSecurityToken;
- $ignore_link = $item['self'] ? '' : $contact_url . '/ignore?t=' . $formSecurityToken;
+ $authorBaseUri = new Uri($item['author-baseurl'] ?? '');
+ if (!empty($item['author-gsid']) && $authorBaseUri->getHost() && !DI::baseUrl()->isLocalUrl($authorBaseUri)) {
+ $ignoreserver_link = 'settings/server/' . $item['author-gsid'] . '/ignore';
$this->l10n->t('View Contact') => $contact_url,
$this->l10n->t('Send PM') => $pm_url,
$this->l10n->t('Block') => $block_link,
$this->l10n->t('View Contact') => $contact_url,
$this->l10n->t('Send PM') => $pm_url,
$this->l10n->t('Block') => $block_link,
- $this->l10n->t('Ignore') => $ignore_link
+ $this->l10n->t('Ignore') => $ignore_link,
+ $this->l10n->t('Collapse') => $collapse_link,
+ $this->l10n->t("Ignore %s server", $authorBaseUri->getHost()) => $ignoreserver_link,
$receivers = [];
// Convert mentions in the body to a unified format
$item['body'] = BBCode::setMentions($item['body'], $item['uid'], $item['network']);
$receivers = [];
// Convert mentions in the body to a unified format
$item['body'] = BBCode::setMentions($item['body'], $item['uid'], $item['network']);
foreach (Tag::getFromBody($item['body'], Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
$contact = Contact::getByURLForUser($tag[2], $item['uid']);
if (empty($contact)) {
foreach (Tag::getFromBody($item['body'], Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
$contact = Contact::getByURLForUser($tag[2], $item['uid']);
if (empty($contact)) {
- $private_forum = $contact['prv'];
- $only_to_forum = ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]);
+ $private_group = $contact['prv'];
+ $only_to_group = ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]);
- $forum_contact = $contact;
- Logger::info('Private forum or exclusive mention', ['url' => $tag[2], 'mention' => $tag[1]]);
+ $group_contact = $contact;
+ Logger::info('Private group or exclusive mention', ['url' => $tag[2], 'mention' => $tag[1]]);
- $forum_contact = $contact;
- Logger::info('Public forum', ['url' => $tag[2], 'mention' => $tag[1]]);
+ $group_contact = $contact;
+ Logger::info('Public group', ['url' => $tag[2], 'mention' => $tag[1]]);
- Logger::info('Post with forum mention will not be converted to a forum post', ['url' => $tag[2], 'mention' => $tag[1]]);
+ Logger::info('Post with group mention will not be converted to a group post', ['url' => $tag[2], 'mention' => $tag[1]]);
- if (($item['gravity'] == ItemModel::GRAVITY_PARENT) && !empty($forum_contact) && ($private_forum || $only_to_forum)) {
- // we tagged a forum in a top level post. Now we change the post
- $item['private'] = $private_forum ? ItemModel::PRIVATE : ItemModel::UNLISTED;
+ if (($item['gravity'] == ItemModel::GRAVITY_PARENT) && !empty($group_contact) && ($private_group || $only_to_group)) {
+ // we tagged a group in a top level post. Now we change the post
+ $item['private'] = $private_group ? ItemModel::PRIVATE : ItemModel::UNLISTED;
+
+ if ($only_to_group) {
+ $cdata = Contact::getPublicAndUserContactID($group_contact['id'], $item['uid']);
+ if (!empty($cdata['user'])) {
+ $item['owner-id'] = $cdata['user'];
+ unset($item['owner-link']);
+ unset($item['owner-name']);
+ unset($item['owner-avatar']);
+ }
if (empty($receivers)) {
// For security reasons direct posts without any receiver will be posts to yourself
$self = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);
if (empty($receivers)) {
// For security reasons direct posts without any receiver will be posts to yourself
$self = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);
- * @param bool $add_media
+ * @param bool $add_media true = Media is added to the body
+ * @param bool $for_display true = The share block is used for display purposes, false = used for connectors, transport to other systems, ...
- $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
+ $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encapsulated_share, $item['body']);
}
}
$item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB));
}
}
$item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB));
$list_array = explode(',', trim($category));
$post['file'] = FileTag::arrayToFile($list_array, 'category');
$list_array = explode(',', trim($category));
$post['file'] = FileTag::arrayToFile($list_array, 'category');
if (!empty($filedas) && is_array($filedas)) {
// append the fileas stuff to the new categories list
$post['file'] .= FileTag::arrayToFile($filedas);
if (!empty($filedas) && is_array($filedas)) {
// append the fileas stuff to the new categories list
$post['file'] .= FileTag::arrayToFile($filedas);
}
$user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
}
$user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
$visibility = $request['visibility'] ?? '';
if ($visibility === 'public') {
// The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
$visibility = $request['visibility'] ?? '';
if ($visibility === 'public') {
// The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
$post['private'] = ItemModel::PRIVATE;
} elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
$post['private'] = ItemModel::UNLISTED;
} else {
$post['private'] = ItemModel::PUBLIC;
}
$post['private'] = ItemModel::PRIVATE;
} elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
$post['private'] = ItemModel::UNLISTED;
} else {
$post['private'] = ItemModel::PUBLIC;
}
- $post['attach'] .= Post\Media::getAttachElement($this->baseURL->get() . '/attach/' . $attachment['id'],
- $attachment['filesize'], $attachment['filetype'], $attachment['filename'] ?? '');
-
- $fields = ['allow_cid' => $post['allow_cid'], 'allow_gid' => $post['allow_gid'],
- 'deny_cid' => $post['deny_cid'], 'deny_gid' => $post['deny_gid']];
+ $post['attach'] .= Post\Media::getAttachElement(
+ $this->baseURL . '/attach/' . $attachment['id'],
+ $attachment['filesize'],
+ $attachment['filetype'],
+ $attachment['filename'] ?? ''
+ );
+
+ $fields = [
+ 'allow_cid' => $post['allow_cid'], 'allow_gid' => $post['allow_gid'],
+ 'deny_cid' => $post['deny_cid'], 'deny_gid' => $post['deny_gid']
+ ];
$condition = ['id' => $attachment_id];
Attach::update($fields, $condition);
}
$condition = ['id' => $attachment_id];
Attach::update($fields, $condition);
}
// embedded bookmark or attachment in post? set bookmark flag
$data = BBCode::getAttachmentData($post['body']);
// embedded bookmark or attachment in post? set bookmark flag
$data = BBCode::getAttachmentData($post['body']);
- if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $post['body'], $match, PREG_SET_ORDER) || isset($data['type']))
- && ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE)) {
+ if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $post['body'], $match, PREG_SET_ORDER) || !empty($data['type']))
+ && ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE)
+ ) {
// Setting the object type if not defined before
if (empty($post['object-type'])) {
$post['object-type'] = ($post['gravity'] == ItemModel::GRAVITY_PARENT) ? Activity\ObjectType::NOTE : Activity\ObjectType::COMMENT;
// Setting the object type if not defined before
if (empty($post['object-type'])) {
$post['object-type'] = ($post['gravity'] == ItemModel::GRAVITY_PARENT) ? Activity\ObjectType::NOTE : Activity\ObjectType::COMMENT;
-
- $objectdata = BBCode::getAttachedData($post['body']);
-
- if ($objectdata['type'] == 'link') {
- $post['object-type'] = Activity\ObjectType::BOOKMARK;
- } elseif ($objectdata['type'] == 'video') {
- $post['object-type'] = Activity\ObjectType::VIDEO;
- } elseif ($objectdata['type'] == 'photo') {
- $post['object-type'] = Activity\ObjectType::IMAGE;
- }
$post['network'] = Protocol::DFRN;
$post['protocol'] = Conversation::PARCEL_DIRECT;
$post['direction'] = Conversation::PUSH;
$post['network'] = Protocol::DFRN;
$post['protocol'] = Conversation::PARCEL_DIRECT;
$post['direction'] = Conversation::PUSH;
- $post['guid'] = System::createUUID();
- $post['uri'] = ItemModel::newURI($post['guid']);
- $post['verb'] = Activity::POST;
- $post['received'] = DateTimeFormat::utcNow();
+ $post['received'] = DateTimeFormat::utcNow();
+ $post['origin'] = true;
+ $post['wall'] = $post['wall'] ?? true;
+ $post['guid'] = $post['guid'] ?? System::createUUID();
+ $post['verb'] = $post['verb'] ?? Activity::POST;
+ $post['uri'] = $post['uri'] ?? ItemModel::newURI($post['guid']);
+ $post['thr-parent'] = $post['thr-parent'] ?? $post['uri'];
+
+ if (empty($post['gravity'])) {
+ $post['gravity'] = ($post['uri'] == $post['thr-parent']) ? ItemModel::GRAVITY_PARENT : ItemModel::GRAVITY_COMMENT;
+ }
+
+ if (!isset($post['allow_cid']) || !isset($post['allow_gid']) || !isset($post['deny_cid']) || !isset($post['deny_gid'])) {
+ $post['allow_cid'] = $owner['allow_cid'];
+ $post['allow_gid'] = $owner['allow_gid'];
+ $post['deny_cid'] = $owner['deny_cid'];
+ $post['deny_gid'] = $owner['deny_gid'];
+ }
+
+ if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
+ $post['private'] = ItemModel::PRIVATE;
+ } elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
+ $post['private'] = ItemModel::UNLISTED;
+ } else {
+ $post['private'] = ItemModel::PUBLIC;
+ }
+
// Convert links with empty descriptions to links without an explicit description
$post['body'] = trim(preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $post['body']));
$post['body'] = $this->bbCodeVideo->transform($post['body']);
// Convert links with empty descriptions to links without an explicit description
$post['body'] = trim(preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $post['body']));
$post['body'] = $this->bbCodeVideo->transform($post['body']);
if ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE) {
// Look for any tags and linkify them
$post = $this->expandTags($post);
if ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE) {
// Look for any tags and linkify them
$post = $this->expandTags($post);
+
+ public function postProcessPost(array $post, array $recipients = [])
+ {
+ if (!\Friendica\Content\Feature::isEnabled($post['uid'], 'explicit_mentions') && ($post['gravity'] == ItemModel::GRAVITY_COMMENT)) {
+ Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
+ }
+
+ Hook::callAll('post_local_end', $post);
+
+ $author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
+
+ foreach ($recipients as $recipient) {
+ $address = trim($recipient);
+ if (!$address) {
+ continue;
+ }
+
+ $this->emailer->send(new ItemCCEMail(
+ $this->app,
+ $this->l10n,
+ $this->baseURL,
+ $post,
+ $address,
+ $author['thumb'] ?? ''
+ ));
+ }
+ }