X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FPost.php;h=3c01028292d0cd2c2ecabf95c2290bf6634dd39a;hb=e3692c01053d4714292449d1170ef2d60ad575d7;hp=17303bd62d7540abd84de44e875fbf9da7d4380c;hpb=9aa0f6f547f92c0c49a8a59da4f0cfede20c4033;p=friendica.git diff --git a/src/Object/Post.php b/src/Object/Post.php index 17303bd62d..3c01028292 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -29,10 +29,10 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Session; -use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Photo; use Friendica\Model\Post as PostModel; use Friendica\Model\Tag; use Friendica\Model\User; @@ -121,6 +121,29 @@ class Post } } + /** + * Fetch the privacy of the post + * + * @param array $item + * @return string + */ + private function fetchPrivacy(array $item):string + { + switch ($item['private']) { + case Item::PRIVATE: + $output = DI::l10n()->t('Private Message'); + break; + case Item::PUBLIC: + $output = DI::l10n()->t('Public Message'); + break; + case Item::UNLISTED: + $output = DI::l10n()->t('Unlisted Message'); + break; + } + + return $output; + } + /** * Get data in a form usable by a conversation template * @@ -170,12 +193,9 @@ class Post $conv = $this->getThread(); - $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) - || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) - ? DI::l10n()->t('Private Message') - : false); - - $connector = !$item['global'] ? DI::l10n()->t('Connector Message') : false; + $privacy = $this->fetchPrivacy($item); + $lock = ($item['private'] == Item::PRIVATE) ? $privacy : false; + $connector = !in_array($item['network'], Protocol::NATIVE_SUPPORT) ? DI::l10n()->t('Connector Message') : false; $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE; $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]); @@ -211,7 +231,7 @@ class Post $origin = $item['origin'] || $item['parent-origin']; - if ($item['pinned']) { + if (!empty($item['featured'])) { $pinned = DI::l10n()->t('Pinned item'); } @@ -229,7 +249,7 @@ class Post ]; } - if (!$item['self']) { + if (!$item['self'] && local_user()) { $block = [ 'blocking' => true, 'block' => DI::l10n()->t('Block %s', $item['author-name']), @@ -323,14 +343,14 @@ class Post if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) { if ($origin) { - $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned'); + $ispinned = ($item['featured'] ? 'pinned' : 'unpinned'); $pin = [ 'do' => DI::l10n()->t('Pin'), 'undo' => DI::l10n()->t('Unpin'), 'toggle' => DI::l10n()->t('Toggle pin status'), - 'classdo' => $item['pinned'] ? 'hidden' : '', - 'classundo' => $item['pinned'] ? '' : 'hidden', + 'classdo' => $item['featured'] ? 'hidden' : '', + 'classundo' => $item['featured'] ? '' : 'hidden', 'pinned' => DI::l10n()->t('Pinned'), ]; } @@ -369,10 +389,12 @@ class Post list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user()); - if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) { + if (!empty($item['title'])) { + $title = $item['title']; + } elseif (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) { $title = ucfirst($item['content-warning']); } else { - $title = $item['title']; + $title = ''; } if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) { @@ -423,6 +445,33 @@ class Post $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)]; } + if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($item['network'], Protocol::FEDERATED)) { + $browsershare = [DI::l10n()->t('Share via ...'), DI::l10n()->t('Share via external services')]; + } else { + $browsershare = null; + } + + if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) { + $owner_avatar = $author_avatar = $item['contact-id']; + $owner_updated = $author_updated = ''; + $owner_thumb = $author_thumb = $item['contact-avatar']; + } else { + $owner_avatar = $item['owner-id']; + $owner_updated = $item['owner-updated']; + $owner_thumb = $item['owner-avatar']; + $author_avatar = $item['author-id']; + $author_updated = $item['author-updated']; + $author_thumb = $item['author-avatar']; + } + + if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) { + $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated); + } + + if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) { + $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated); + } + $tmp_item = [ 'template' => $this->getTemplate(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), @@ -454,7 +503,7 @@ class Post 'profile_url' => $profile_link, 'name' => $profile_name, 'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken), - 'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)), + 'thumb' => DI::baseUrl()->remove($author_thumb), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title, @@ -463,16 +512,18 @@ class Post 'app' => $item['app'], 'created' => $ago, 'lock' => $lock, + 'private' => $item['private'], + 'privacy' => $privacy, 'connector' => $connector, 'location_html' => $location_html, 'indent' => $indent, 'shiny' => $shiny, 'owner_self' => $item['author-link'] == Session::get('my_url'), 'owner_url' => $this->getOwnerUrl(), - 'owner_photo' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)), + 'owner_photo' => DI::baseUrl()->remove($owner_thumb), 'owner_name' => $this->getOwnerName(), 'plink' => Item::getPlink($item), - 'browsershare' => DI::l10n()->t('Share'), + 'browsershare' => $browsershare, 'edpost' => $edpost, 'ispinned' => $ispinned, 'pin' => $pin, @@ -499,8 +550,8 @@ class Post 'thread_level' => $thread_level, 'edited' => $edited, 'network' => $item["network"], - 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']), - 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']), + 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']), + 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']), 'received' => $item['received'], 'commented' => $item['commented'], 'created_date' => $item['created'], @@ -868,21 +919,20 @@ class Post } $owner = User::getOwnerDataById($a->getLoggedInUserId()); + $item = $this->getData(); - if (!Feature::isEnabled(local_user(), 'explicit_mentions')) { - return ''; + if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) { + $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n"; + } else { + $text = ''; } - $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity'], ['id' => $this->getId()]); - if (!DBA::isResult($item) || empty($item['author-addr'])) { - // Should not happen - return ''; + if (!Feature::isEnabled(local_user(), 'explicit_mentions')) { + return $text; } if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) { - $text = '@' . $item['author-addr'] . ' '; - } else { - $text = ''; + $text .= '@' . $item['author-addr'] . ' '; } $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]); @@ -933,7 +983,7 @@ class Post $uid = $conv->getProfileOwner(); $parent_uid = $this->getDataValue('uid'); - $contact = Contact::getById($a->getContactId()); + $owner = User::getOwnerDataById($a->getLoggedInUserId()); $default_text = $this->getDefaultText(); @@ -952,9 +1002,9 @@ class Post '$qcomment' => $qcomment, '$default' => $default_text, '$profile_uid' => $uid, - '$mylink' => DI::baseUrl()->remove($contact['url'] ?? ''), + '$mylink' => DI::baseUrl()->remove($owner['url'] ?? ''), '$mytitle' => DI::l10n()->t('This is you'), - '$myphoto' => DI::baseUrl()->remove($contact['thumb'] ?? ''), + '$myphoto' => DI::baseUrl()->remove($owner['thumb'] ?? ''), '$comment' => DI::l10n()->t('Comment'), '$submit' => DI::l10n()->t('Submit'), '$loading' => DI::l10n()->t('Loading...'),