]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact.php
Merge pull request #10627 from annando/like-announce
[friendica.git] / src / Module / Contact.php
index 17b598a98bd994874c66736715b1534963da2e2c..ae7c77d9927b0b23dc6a692529592dbacc3db774 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -27,7 +27,6 @@ use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Widget;
-use Friendica\Core\ACL;
 use Friendica\Core\Hook;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
@@ -106,13 +105,13 @@ class Contact extends BaseModule
                }
 
                // @TODO: Replace with parameter from router
-               if ($a->argv[1] === 'batch') {
+               if (DI::args()->getArgv()[1] === 'batch') {
                        self::batchActions();
                        return;
                }
 
                // @TODO: Replace with parameter from router
-               $contact_id = intval($a->argv[1]);
+               $contact_id = intval(DI::args()->getArgv()[1]);
                if (!$contact_id) {
                        return;
                }
@@ -156,12 +155,6 @@ class Contact extends BaseModule
                if (!DBA::isResult($r)) {
                        notice(DI::l10n()->t('Failed to update contact record.'));
                }
-
-               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
-               if (DBA::isResult($contact)) {
-                       $a->data['contact'] = $contact;
-               }
-
                return;
        }
 
@@ -175,15 +168,16 @@ class Contact extends BaseModule
                }
 
                if ($contact['network'] == Protocol::OSTATUS) {
-                       $user = Model\User::getById($contact['uid']);
-                       $result = Model\Contact::createFromProbe($user, $contact['url'], false, $contact['network']);
+                       $result = Model\Contact::createFromProbeForUser($contact['uid'], $contact['url'], $contact['network']);
 
                        if ($result['success']) {
                                DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
                        }
-               } else {
+
                        // pull feed and consume it, which should subscribe to the hub.
                        Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
+               } else {
+                       Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id);
                }
        }
 
@@ -275,13 +269,13 @@ class Contact extends BaseModule
 
                $contact = null;
                // @TODO: Replace with parameter from router
-               if ($a->argc == 2 && intval($a->argv[1])
-                       || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
+               if (DI::args()->getArgc() == 2 && intval(DI::args()->getArgv()[1])
+                       || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])
                ) {
-                       $contact_id = intval($a->argv[1]);
+                       $contact_id = intval(DI::args()->getArgv()[1]);
 
                        // Ensure to use the user contact when the public contact was provided
-                       $data = Model\Contact::getPublicAndUserContacID($contact_id, local_user());
+                       $data = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
                        if (!empty($data['user']) && ($contact_id == $data['public'])) {
                                $contact_id = $data['user'];
                        }
@@ -297,51 +291,14 @@ class Contact extends BaseModule
                if (DBA::isResult($contact)) {
                        if ($contact['self']) {
                                // @TODO: Replace with parameter from router
-                               if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
+                               if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) {
                                        DI::baseUrl()->redirect('profile/' . $contact['nick']);
                                } else {
                                        DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile');
                                }
                        }
 
-                       $a->data['contact'] = $contact;
-
-                       if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
-                               $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
-                       } else {
-                               $network_link = '';
-                       }
-
-                       $follow_link = '';
-                       $unfollow_link = '';
-                       if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
-                               if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::SHARING, Model\Contact::FRIEND])) {
-                                       $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
-                               } elseif(!$contact['pending']) {
-                                       $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
-                               }
-                       }
-
-                       $wallmessage_link = '';
-                       if ($contact['uid'] && Model\Contact::canReceivePrivateMessages($contact)) {
-                               $wallmessage_link = 'message/new/' . $contact['id'];
-                       }
-
-                       $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
-                               '$name'         => $contact['name'],
-                               '$photo'        => Model\Contact::getPhoto($contact),
-                               '$url'          => Model\Contact::magicLinkByContact($contact, $contact['url']),
-                               '$addr'         => $contact['addr'] ?? '',
-                               '$network_link' => $network_link,
-                               '$network'      => DI::l10n()->t('Network:'),
-                               '$account_type' => Model\Contact::getAccountType($contact),
-                               '$follow'       => DI::l10n()->t('Follow'),
-                               '$follow_link'   => $follow_link,
-                               '$unfollow'     => DI::l10n()->t('Unfollow'),
-                               '$unfollow_link' => $unfollow_link,
-                               '$wallmessage'  => DI::l10n()->t('Message'),
-                               '$wallmessage_link' => $wallmessage_link,
-                       ]);
+                       $vcard_widget = Widget\VCard::getHTML($contact);
 
                        $findpeople_widget = '';
                        $follow_widget = '';
@@ -384,14 +341,14 @@ class Contact extends BaseModule
                        return Login::form();
                }
 
-               if ($a->argc == 3) {
-                       $contact_id = intval($a->argv[1]);
+               if (DI::args()->getArgc() == 3) {
+                       $contact_id = intval(DI::args()->getArgv()[1]);
                        if (!$contact_id) {
                                throw new BadRequestException();
                        }
 
                        // @TODO: Replace with parameter from router
-                       $cmd = $a->argv[2];
+                       $cmd = DI::args()->getArgv()[2];
 
                        $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
                        if (!DBA::isResult($orig_record)) {
@@ -411,6 +368,10 @@ class Contact extends BaseModule
                        }
 
                        if ($cmd === 'block') {
+                               if (public_contact() === $contact_id) {
+                                       throw new BadRequestException(DI::l10n()->t('You can\'t block yourself'));
+                               }
+
                                self::blockContact($contact_id);
 
                                $blocked = Model\Contact\User::isBlocked($contact_id, local_user());
@@ -421,6 +382,10 @@ class Contact extends BaseModule
                        }
 
                        if ($cmd === 'ignore') {
+                               if (public_contact() === $contact_id) {
+                                       throw new BadRequestException(DI::l10n()->t('You can\'t ignore yourself'));
+                               }
+
                                self::ignoreContact($contact_id);
 
                                $ignored = Model\Contact\User::isIgnored($contact_id, local_user());
@@ -478,9 +443,7 @@ class Contact extends BaseModule
 
                $_SESSION['return_path'] = DI::args()->getQueryString();
 
-               if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
-                       $contact = $a->data['contact'];
-
+               if (!empty($contact)) {
                        DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
                                '$baseurl' => DI::baseUrl()->get(true),
                        ]);
@@ -516,7 +479,7 @@ class Contact extends BaseModule
 
                        $relation_text = sprintf($relation_text, $contact['name']);
 
-                       $url = Model\Contact::magicLink($contact['url']);
+                       $url = Model\Contact::magicLinkByContact($contact);
                        if (strpos($url, 'redir/') === 0) {
                                $sparkle = ' class="sparkle" ';
                        } else {
@@ -528,13 +491,13 @@ class Contact extends BaseModule
                        $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? DI::l10n()->t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
 
                        if ($contact['last-update'] > DBA::NULL_DATETIME) {
-                               $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? DI::l10n()->t('(Update was successful)') : DI::l10n()->t('(Update was not successful)'));
+                               $last_update .= ' ' . ($contact['failed'] ? DI::l10n()->t('(Update was not successful)') : DI::l10n()->t('(Update was successful)'));
                        }
                        $lblsuggest = (($contact['network'] === Protocol::DFRN) ? DI::l10n()->t('Suggest friends') : '');
 
                        $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
 
-                       $nettype = DI::l10n()->t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']));
+                       $nettype = DI::l10n()->t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']));
 
                        // tabs
                        $tab_str = self::getTabsHTML($contact, self::TAB_PROFILE);
@@ -560,13 +523,23 @@ class Contact extends BaseModule
                        // Disable remote self for everything except feeds.
                        // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
                        // Problem is, you couldn't reply to both networks.
-                       $allow_remote_self = in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
+                       $allow_remote_self = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
                                && DI::config()->get('system', 'allow_users_remote_self');
 
                        if ($contact['network'] == Protocol::FEED) {
-                               $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '1' => DI::l10n()->t('Mirror as forwarded posting'), '2' => DI::l10n()->t('Mirror as my own posting')];
+                               $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
+                                       Model\Contact::MIRROR_FORWARDED => DI::l10n()->t('Mirror as forwarded posting'),
+                                       Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
+                       } elseif (in_array($contact['network'], [Protocol::ACTIVITYPUB])) {
+                               $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
+                               Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
+                       } elseif (in_array($contact['network'], [Protocol::DFRN])) {
+                               $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
+                               Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting'),
+                               Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
                        } else {
-                               $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
+                               $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
+                                       Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
                        }
 
                        $poll_interval = null;
@@ -630,11 +603,13 @@ class Contact extends BaseModule
                                '$profileurllabel'=> DI::l10n()->t('Profile URL'),
                                '$profileurl'     => $contact['url'],
                                '$account_type'   => Model\Contact::getAccountType($contact),
-                               '$location'       => BBCode::convert($contact['location']),
+                               '$location'       => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
                                '$location_label' => DI::l10n()->t('Location:'),
-                               '$xmpp'           => BBCode::convert($contact['xmpp']),
+                               '$xmpp'           => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
                                '$xmpp_label'     => DI::l10n()->t('XMPP:'),
-                               '$about'          => BBCode::convert($contact['about'], false),
+                               '$matrix'         => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['matrix']),
+                               '$matrix_label'   => DI::l10n()->t('Matrix:'),
+                               '$about'          => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'], BBCode::EXTERNAL),
                                '$about_label'    => DI::l10n()->t('About:'),
                                '$keywords'       => $contact['keywords'],
                                '$keywords_label' => DI::l10n()->t('Tags:'),
@@ -649,7 +624,7 @@ class Contact extends BaseModule
                                        $contact['remote_self'],
                                        DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
                                        $remote_self_options
-                               ],      
+                               ],
                        ]);
 
                        $arr = ['contact' => $contact, 'output' => $o];
@@ -662,7 +637,7 @@ class Contact extends BaseModule
                $sql_values = [local_user()];
 
                // @TODO: Replace with parameter from router
-               $type = $a->argv[1] ?? '';
+               $type = DI::args()->getArgv()[1] ?? '';
 
                switch ($type) {
                        case 'blocked':
@@ -679,7 +654,7 @@ class Contact extends BaseModule
                                array_unshift($sql_values, 0);
                                break;
                        case 'archived':
-                               $sql_extra = " AND (`archive` OR `failed`) AND NOT `blocked` AND NOT `pending`";
+                               $sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
                                break;
                        case 'pending':
                                $sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
@@ -687,7 +662,7 @@ class Contact extends BaseModule
                                $sql_values[] = Model\Contact::SHARING;
                                break;
                        default:
-                               $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending` AND NOT `failed`";
+                               $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`";
                                break;
                }
 
@@ -895,7 +870,7 @@ class Contact extends BaseModule
        public static function getTabsHTML(array $contact, int $active_tab)
        {
                $cid = $pcid = $contact['id'];
-               $data = Model\Contact::getPublicAndUserContacID($contact['id'], local_user());
+               $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user());
                if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
                        $cid = $data['user'];
                } elseif (!empty($data['public'])) {
@@ -937,7 +912,7 @@ class Contact extends BaseModule
                        ],
                ];
 
-               if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && ($cid != $pcid)) {
+               if (!empty($contact['network']) && in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && ($cid != $pcid)) {
                        $tabs[] = ['label' => DI::l10n()->t('Advanced'),
                                'url'   => 'contact/' . $cid . '/advanced/',
                                'sel'   => (($active_tab == self::TAB_ADVANCED) ? 'active' : ''),
@@ -960,18 +935,7 @@ class Contact extends BaseModule
                if (!$update) {
                        // We need the editor here to be able to reshare an item.
                        if (local_user()) {
-                               $x = [
-                                       'is_owner' => true,
-                                       'allow_location' => $a->user['allow_location'],
-                                       'default_location' => $a->user['default-location'],
-                                       'nickname' => $a->user['nickname'],
-                                       'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
-                                       'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true),
-                                       'bang' => '',
-                                       'visitor' => 'block',
-                                       'profile_uid' => local_user(),
-                               ];
-                               $o = status_editor($a, $x, 0, true);
+                               $o = status_editor($a, [], 0, true);
                        }
                }
 
@@ -982,11 +946,11 @@ class Contact extends BaseModule
                }
 
                if (DBA::isResult($contact)) {
-                       DI::page()['aside'] = '';
-
                        if (!$update) {
                                $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
-                               Model\Profile::load($a, '', $profiledata, true);
+                               DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
+                       } else {
+                               DI::page()['aside'] = '';
                        }
 
                        if ($contact['uid'] == 0) {
@@ -1006,15 +970,13 @@ class Contact extends BaseModule
                $o = self::getTabsHTML($contact, self::TAB_POSTS);
 
                if (DBA::isResult($contact)) {
-                       DI::page()['aside'] = '';
-
                        $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
 
                        if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
                                $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
                        }
 
-                       Model\Profile::load($a, '', $profiledata, true);
+                       DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
 
                        if ($contact['uid'] == 0) {
                                $o .= Model\Contact::getPostsFromId($contact['id']);
@@ -1064,7 +1026,7 @@ class Contact extends BaseModule
                        }
                }
 
-               $url = Model\Contact::magicLink($contact['url']);
+               $url = Model\Contact::magicLinkByContact($contact);
 
                if (strpos($url, 'redir/') === 0) {
                        $sparkle = ' class="sparkle" ';
@@ -1091,17 +1053,17 @@ class Contact extends BaseModule
                        'url'          => $url,
                        'img_hover'    => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
                        'photo_menu'   => Model\Contact::photoMenu($contact),
-                       'thumb'        => Model\Contact::getThumb($contact),
+                       'thumb'        => Model\Contact::getThumb($contact, true),
                        'alt_text'     => $alt_text,
                        'name'         => $contact['name'],
                        'nick'         => $contact['nick'],
-                       'details'      => $contact['location'], 
+                       'details'      => $contact['location'],
                        'tags'         => $contact['keywords'],
                        'about'        => $contact['about'],
                        'account_type' => Model\Contact::getAccountType($contact),
                        'sparkle'      => $sparkle,
                        'itemurl'      => ($contact['addr'] ?? '') ?: $contact['url'],
-                       'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']),
+                       'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
                ];
        }
 
@@ -1139,7 +1101,7 @@ class Contact extends BaseModule
                        ];
                }
 
-               if (in_array($contact['network'], Protocol::FEDERATED)) {
+               if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                        $contact_actions['updateprofile'] = [
                                'label' => DI::l10n()->t('Refetch contact data'),
                                'url'   => 'contact/' . $contact['id'] . '/updateprofile',