use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Group;
-use Friendica\Model\Item as ModelItem;
+use Friendica\Model\Item as ItemModel;
use Friendica\Model\Photo;
use Friendica\Model\Tag;
use Friendica\Model\Post;
$sub_link = $contact_url = $pm_url = $status_link = '';
$photos_link = $posts_link = $block_link = $ignore_link = '';
- if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
+ if (local_user() && local_user() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
];
if (!empty($item['language'])) {
- $menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ModelItem::getLanguageMessage($item) . '\');';
+ $menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ItemModel::getLanguageMessage($item) . '\');';
}
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
}
$item['inform'] .= 'cid:' . $contact['id'];
- if (($item['gravity'] == GRAVITY_COMMENT) || empty($contact['cid']) || ($contact['contact-type'] != Contact::TYPE_COMMUNITY)) {
+ if (($item['gravity'] == ItemModel::GRAVITY_COMMENT) || empty($contact['cid']) || ($contact['contact-type'] != Contact::TYPE_COMMUNITY)) {
continue;
}
}
Logger::info('Got inform', ['inform' => $item['inform']]);
- if (($item['gravity'] == GRAVITY_PARENT) && !empty($forum_contact) && ($private_forum || $only_to_forum)) {
+ 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 ? ModelItem::PRIVATE : ModelItem::UNLISTED;
+ $item['private'] = $private_forum ? ItemModel::PRIVATE : ItemModel::UNLISTED;
if ($only_to_forum) {
$item['postopts'] = '';
$item['allow_cid'] = '';
$item['allow_gid'] = '';
}
- } elseif ($setPermissions && ($item['gravity'] == GRAVITY_PARENT)) {
+ } elseif ($setPermissions && ($item['gravity'] == ItemModel::GRAVITY_PARENT)) {
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]);
$receivers[] = $self['id'];
}
- $item['private'] = ModelItem::PRIVATE;
+ $item['private'] = ItemModel::PRIVATE;
$item['allow_cid'] = '';
$item['allow_gid'] = '';
$item['deny_cid'] = '';
*
* @param string $url
* @param integer $uid
+ * @param bool $add_media
* @return string
*/
- public function createSharedPostByUrl(string $url, int $uid = 0): string
+ public function createSharedPostByUrl(string $url, int $uid = 0, bool $add_media = false): string
{
if (!empty($uid)) {
- $id = ModelItem::searchByLink($url, $uid);
+ $id = ItemModel::searchByLink($url, $uid);
}
if (empty($id)) {
- $id = ModelItem::fetchByLink($url);
+ $id = ItemModel::fetchByLink($url);
}
if (!$id) {
return '';
}
- return $this->createSharedBlockByArray($shared_item);
+ return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
*
* @param integer $UriId
* @param integer $uid
+ * @param bool $add_media
* @return string
*/
- public function createSharedPostByUriId(int $UriId, int $uid = 0): string
+ public function createSharedPostByUriId(int $UriId, int $uid = 0, bool $add_media = false): string
{
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network'];
- $shared_item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [ModelItem::PUBLIC, ModelItem::UNLISTED]]);
+ $shared_item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [ItemModel::PUBLIC, ItemModel::UNLISTED]]);
if (!DBA::isResult($shared_item)) {
Logger::notice('Post does not exist.', ['uri-id' => $UriId, 'uid' => $uid]);
return '';
}
- return $this->createSharedBlockByArray($shared_item);
+ return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
*
* @param string $guid
* @param integer $uid
+ * @param bool $add_media
* @return string
*/
- public function createSharedPostByGuid(string $guid, int $uid = 0, string $host = ''): string
+ public function createSharedPostByGuid(string $guid, int $uid = 0, string $host = '', bool $add_media = false): string
{
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network'];
- $shared_item = Post::selectFirst($fields, ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [ModelItem::PUBLIC, ModelItem::UNLISTED]]);
+ $shared_item = Post::selectFirst($fields, ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [ItemModel::PUBLIC, ItemModel::UNLISTED]]);
if (!DBA::isResult($shared_item) && !empty($host) && Diaspora::storeByGuid($guid, $host, true)) {
Logger::debug('Fetched post', ['guid' => $guid, 'host' => $host, 'uid' => $uid]);
- $shared_item = Post::selectFirst($fields, ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [ModelItem::PUBLIC, ModelItem::UNLISTED]]);
+ $shared_item = Post::selectFirst($fields, ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [ItemModel::PUBLIC, ItemModel::UNLISTED]]);
} elseif (DBA::isResult($shared_item)) {
Logger::debug('Found existing post', ['guid' => $guid, 'host' => $host, 'uid' => $uid]);
}
return '';
}
- return $this->createSharedBlockByArray($shared_item);
+ return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
* Add a share block for the given item array
*
* @param array $item
+ * @param bool $add_media
* @return string
*/
- public function createSharedBlockByArray(array $item): string
+ public function createSharedBlockByArray(array $item, bool $add_media = false): 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']);
+ } elseif ($add_media) {
+ $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']);
$shared = BBCode::fetchShareAttributes($item['body']);
- $item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $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']);
- if (!empty($encaspulated_share)) {
- $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
- }
+ if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid'], 0, '', $add_media))) {
+ $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
}
-
+
$item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB));
}