X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FPost.php;h=089556a1fa038b361e430f93d1b74f1ce1cead02;hb=09aa496387ae732a2a27ab8d963f2e24192082cd;hp=b89a54a874b6239b76b175bb98007d82f47b05e3;hpb=8c328a3c60d3bcbc8b091158383bf829064d2c9c;p=friendica.git diff --git a/src/Object/Post.php b/src/Object/Post.php index b89a54a874..089556a1fa 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -1,6 +1,6 @@ getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE; - $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER]); + $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]); + + // On Diaspora only toplevel posts can be reshared + if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != GRAVITY_PARENT)) { + $announceable = false; + } $edpost = false; @@ -202,48 +208,44 @@ class Post $dropping = true; } - $origin = $item['origin']; + $origin = $item['origin'] || $item['parent-origin']; - if (!$origin) { - /// @todo This shouldn't be done as query here, but better during the data creation. - // it is now done here, since during the RC phase we shouldn't make to intense changes. - $parent = Item::selectFirst(['origin'], ['id' => $item['parent']]); - if (DBA::isResult($parent)) { - $origin = $parent['origin']; - } - } elseif ($item['pinned']) { - $pinned = DI::l10n()->t('pinned item'); + if ($item['pinned']) { + $pinned = DI::l10n()->t('Pinned item'); } - if ($origin && ($item['gravity'] != GRAVITY_PARENT) && ($item['network'] == Protocol::ACTIVITYPUB)) { - // ActivityPub doesn't allow removal of remote comments - $delete = DI::l10n()->t('Delete locally'); - } else { - // Showing the one or the other text, depending upon if we can only hide it or really delete it. - $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally'); - } + // Showing the one or the other text, depending upon if we can only hide it or really delete it. + $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally'); $drop = false; + $block = false; if (local_user()) { $drop = [ 'dropping' => $dropping, 'pagedrop' => $item['pagedrop'], - 'select' => DI::l10n()->t('Select'), - 'delete' => $delete, + 'select' => DI::l10n()->t('Select'), + 'delete' => $delete, + ]; + } + + if (!$item['self']) { + $block = [ + 'blocking' => true, + 'block' => DI::l10n()->t('Block %s', $item['author-name']), + 'author_id' => $item['author-id'], ]; } - $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false); + $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t('Save to folder') : false); $profile_name = $item['author-name']; if (!empty($item['author-link']) && empty($item['author-name'])) { $profile_name = $item['author-link']; } - $author = ['uid' => 0, 'id' => $item['author-id'], - 'network' => $item['author-network'], 'url' => $item['author-link']]; - if (Session::isAuthenticated()) { + $author = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; $profile_link = Contact::magicLinkByContact($author); } else { $profile_link = $item['author-link']; @@ -275,8 +277,8 @@ class Post $responses = []; foreach ($response_verbs as $value => $verb) { $responses[$verb] = [ - 'self' => $conv_responses[$verb][$item['uri'] . '-self'] ?? 0, - 'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_like($conv_responses[$verb][$item['uri']], $conv_responses[$verb][$item['uri'] . '-l'], $verb, $item['uri']) : '', + 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0, + 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? format_activity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '', ]; } @@ -295,15 +297,15 @@ class Post if ($this->isToplevel()) { if(local_user()) { - $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]); - if (DBA::isResult($thread)) { + $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user()); + if ($item['mention'] || $ignored) { $ignore = [ - 'do' => DI::l10n()->t("ignore thread"), - 'undo' => DI::l10n()->t("unignore thread"), - 'toggle' => DI::l10n()->t("toggle ignore status"), - 'classdo' => $thread['ignored'] ? "hidden" : "", - 'classundo' => $thread['ignored'] ? "" : "hidden", - 'ignored' => DI::l10n()->t('ignored'), + 'do' => DI::l10n()->t('Ignore thread'), + 'undo' => DI::l10n()->t('Unignore thread'), + 'toggle' => DI::l10n()->t('Toggle ignore status'), + 'classdo' => $ignored ? "hidden" : "", + 'classundo' => $ignored ? "" : "hidden", + 'ignored' => DI::l10n()->t('Ignored'), ]; } @@ -312,28 +314,28 @@ class Post $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned'); $pin = [ - 'do' => DI::l10n()->t('pin'), - 'undo' => DI::l10n()->t('unpin'), - 'toggle' => DI::l10n()->t('toggle pin status'), + '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', - 'pinned' => DI::l10n()->t('pinned'), + 'pinned' => DI::l10n()->t('Pinned'), ]; } $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = [ - 'do' => DI::l10n()->t("add star"), - 'undo' => DI::l10n()->t("remove star"), - 'toggle' => DI::l10n()->t("toggle star status"), + 'do' => DI::l10n()->t('Add star'), + 'undo' => DI::l10n()->t('Remove star'), + 'toggle' => DI::l10n()->t('Toggle star status'), 'classdo' => $item['starred'] ? "hidden" : "", 'classundo' => $item['starred'] ? "" : "hidden", - 'starred' => DI::l10n()->t('starred'), + 'starred' => DI::l10n()->t('Starred'), ]; $tagger = [ - 'add' => DI::l10n()->t("add tag"), + 'add' => DI::l10n()->t('Add tag'), 'class' => "", ]; } @@ -343,13 +345,14 @@ class Post } if ($conv->isWritable()) { - $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t("like")]; - $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")]; + $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t('Like')]; + $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t('Dislike')]; if ($shareable) { - $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('Share')]; + $buttons['share'] = [DI::l10n()->t('Quote share this'), DI::l10n()->t('Quote Share')]; } if ($announceable) { - $buttons['announce'] = [DI::l10n()->t('Announce this'), DI::l10n()->t('Announce')]; + $buttons['announce'] = [DI::l10n()->t('Reshare this'), DI::l10n()->t('Reshare')]; + $buttons['unannounce'] = [DI::l10n()->t('Cancel your Reshare'), DI::l10n()->t('Unshare')]; } } @@ -398,9 +401,13 @@ class Post } // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments - if (($item['network'] != Protocol::DIASPORA) && empty($comment) && !empty(Session::get('remote_comment'))) { - $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('remote comment'), + if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(Session::get('remote_comment'))) { + $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('Remote comment'), str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))]; + + // Ensure to either display the remote comment or the local activities + $buttons = []; + $comment_html = ''; } else { $remote_comment = ''; } @@ -424,6 +431,8 @@ class Post $tmp_item = [ 'template' => $this->getTemplate(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), + 'comment_firstcollapsed' => false, + 'comment_lastcollapsed' => false, 'suppress_tags' => DI::config()->get('system', 'suppress_tags'), 'tags' => $tags['tags'], 'hashtags' => $tags['hashtags'], @@ -450,7 +459,7 @@ class Post 'profile_url' => $profile_link, 'name' => $profile_name, 'item_photo_menu_html' => item_photo_menu($item), - 'thumb' => DI::baseUrl()->remove($item['author-avatar']), + 'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title, @@ -464,7 +473,7 @@ class Post 'shiny' => $shiny, 'owner_self' => $item['author-link'] == Session::get('my_url'), 'owner_url' => $this->getOwnerUrl(), - 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']), + 'owner_photo' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)), 'owner_name' => $this->getOwnerName(), 'plink' => Item::getPlink($item), 'edpost' => $edpost, @@ -478,6 +487,7 @@ class Post 'filer' => $filer, 'language' => $languages, 'drop' => $drop, + 'block' => $block, 'vote' => $buttons, 'like_html' => $responses['like']['output'], 'dislike_html' => $responses['dislike']['output'], @@ -539,10 +549,7 @@ class Post } } - if ($this->isToplevel()) { - $result['total_comments_num'] = "$total_children"; - $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children); - } + $result['total_comments_num'] = $this->isToplevel() ? $total_children : 0; $result['private'] = $item['private']; $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : ''); @@ -869,13 +876,13 @@ class Post return ''; } - $item = Item::selectFirst(['author-addr', 'uri-id'], ['id' => $this->getId()]); + $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 ($item['author-addr'] != $owner['addr']) { + if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) { $text = '@' . $item['author-addr'] . ' '; } else { $text = ''; @@ -883,8 +890,13 @@ class Post $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]); foreach ($terms as $term) { + if (!$term['url']) { + DI::logger()->warning('Mention term with no URL', ['term' => $term]); + continue; + } + $profile = Contact::getByURL($term['url'], false, ['addr', 'contact-type']); - if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) && + if (!empty($profile['addr']) && (($profile['contact-type'] ?? Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) && ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) { $text .= '@' . $profile['addr'] . ' '; } @@ -941,9 +953,9 @@ class Post '$qcomment' => $qcomment, '$default' => $default_text, '$profile_uid' => $uid, - '$mylink' => DI::baseUrl()->remove($a->contact['url']), + '$mylink' => DI::baseUrl()->remove($a->contact['url'] ?? ''), '$mytitle' => DI::l10n()->t('This is you'), - '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']), + '$myphoto' => DI::baseUrl()->remove($a->contact['thumb'] ?? ''), '$comment' => DI::l10n()->t('Comment'), '$submit' => DI::l10n()->t('Submit'), '$loading' => DI::l10n()->t('Loading...'), @@ -993,8 +1005,7 @@ class Post // This will have been stored in $a->page_contact by our calling page. // Put this person as the wall owner of the wall-to-wall notice. - $this->owner_url = Contact::magicLink($a->page_contact['url']); - $this->owner_photo = $a->page_contact['thumb']; + $this->owner_url = Contact::magicLinkByContact($a->page_contact); $this->owner_name = $a->page_contact['name']; $this->wall_to_wall = true; } elseif ($this->getDataValue('owner-link')) { @@ -1012,7 +1023,6 @@ class Post // But it could be somebody else with the same name. It just isn't highly likely. - $this->owner_photo = $this->getDataValue('owner-avatar'); $this->owner_name = $this->getDataValue('owner-name'); $this->wall_to_wall = true; @@ -1028,7 +1038,6 @@ class Post if (!$this->wall_to_wall) { $this->setTemplate('wall'); $this->owner_url = ''; - $this->owner_photo = ''; $this->owner_name = ''; } }