]> git.mxchange.org Git - friendica.git/blobdiff - mod/contacts.php
Merge pull request #5862 from nupplaphil/rename_App_Methods
[friendica.git] / mod / contacts.php
index 38896a611a3c7d08f88a480bf2d31dd36665534a..4e149ab74fa4c448cc0e1fcaa847e1551ce18dfb 100644 (file)
@@ -22,6 +22,7 @@ use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Core\ACL;
+use Friendica\Module\Login;
 
 function contacts_init(App $a)
 {
@@ -47,6 +48,11 @@ function contacts_init(App $a)
                if (!DBA::isResult($contact)) {
                        $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]);
                }
+
+               // Don't display contacts that are about to be deleted
+               if ($contact['network'] == Protocol::PHANTOM) {
+                       $contact = false;
+               }
        }
 
        if (DBA::isResult($contact)) {
@@ -112,21 +118,16 @@ function contacts_init(App $a)
                '$baseurl' => System::baseUrl(true),
                '$base' => $base
        ]);
-
-       $tpl = get_markup_template("contacts-end.tpl");
-       $a->page['end'] .= replace_macros($tpl, [
-               '$baseurl' => System::baseUrl(true),
-               '$base' => $base
-       ]);
 }
 
 function contacts_batch_actions(App $a)
 {
-       $contacts_id = $_POST['contact_batch'];
-       if (!is_array($contacts_id)) {
+       if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
                return;
        }
 
+       $contacts_id = $_POST['contact_batch'];
+
        $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
                implode(",", $contacts_id),
                intval(local_user())
@@ -162,11 +163,7 @@ function contacts_batch_actions(App $a)
                info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
        }
 
-       if (x($_SESSION, 'return_url')) {
-               goaway('' . $_SESSION['return_url']);
-       } else {
-               goaway('contacts');
-       }
+       goaway('contacts');
 }
 
 function contacts_post(App $a)
@@ -367,7 +364,7 @@ function _contact_drop($orig_record)
                return;
        }
 
-       Contact::terminateFriendship($r[0], $orig_record);
+       Contact::terminateFriendship($r[0], $orig_record, true);
        Contact::remove($orig_record['id']);
 }
 
@@ -379,7 +376,7 @@ function contacts_content(App $a, $update = 0)
 
        if (!local_user()) {
                notice(L10n::t('Permission denied.') . EOL);
-               return;
+               return Login::form();
        }
 
        if ($a->argc == 3) {
@@ -470,20 +467,13 @@ function contacts_content(App $a, $update = 0)
                        }
                        // Now check how the user responded to the confirmation query
                        if (x($_REQUEST, 'canceled')) {
-                               if (x($_SESSION, 'return_url')) {
-                                       goaway('' . $_SESSION['return_url']);
-                               } else {
-                                       goaway('contacts');
-                               }
+                               goaway('contacts');
                        }
 
                        _contact_drop($orig_record);
                        info(L10n::t('Contact has been removed.') . EOL);
-                       if (x($_SESSION, 'return_url')) {
-                               goaway('' . $_SESSION['return_url']);
-                       } else {
-                               goaway('contacts');
-                       }
+
+                       goaway('contacts');
                        return; // NOTREACHED
                }
                if ($cmd === 'posts') {
@@ -503,9 +493,6 @@ function contacts_content(App $a, $update = 0)
                $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
                        '$baseurl' => System::baseUrl(true),
                ]);
-               $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), [
-                       '$baseurl' => System::baseUrl(true),
-               ]);
 
                $contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user());
                $contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user());
@@ -536,7 +523,7 @@ function contacts_content(App $a, $update = 0)
                        $relation_text = '';
                }
 
-               if (!in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+               if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
                        $relation_text = "";
                }
 
@@ -595,17 +582,12 @@ function contacts_content(App $a, $update = 0)
                /// @todo Only show the following link with DFRN when the remote version supports it
                $follow = '';
                $follow_text = '';
-               if ($contact['network'] != Protocol::STATUSNET) {
-                       if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
+               if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
+                       if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                                $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
                                $follow_text = L10n::t("Disconnect/Unfollow");
-                       } else {
-                               $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
-                               $follow_text = L10n::t("Connect/Follow");
                        }
-               }
-
-               if ($contact['uid'] == 0) {
+               } else {
                        $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
                        $follow_text = L10n::t("Connect/Follow");
                }
@@ -654,15 +636,15 @@ function contacts_content(App $a, $update = 0)
                        '$follow_text' => $follow_text,
                        '$profile_select' => $profile_select,
                        '$contact_id' => $contact['id'],
-                       '$block_text' => (($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
-                       '$ignore_text' => (($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
-                       '$insecure' => (($contact['network'] !== Protocol::DFRN && $contact['network'] !== Protocol::MAIL && $contact['network'] !== Protocol::DIASPORA) ? $insecure : ''),
+                       '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
+                       '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
+                       '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
                        '$info' => $contact['info'],
                        '$cinfo' => ['info', '', $contact['info'], ''],
-                       '$blocked' => (($contact['blocked']) ? L10n::t('Currently blocked') : ''),
-                       '$ignored' => (($contact['readonly']) ? L10n::t('Currently ignored') : ''),
-                       '$archived' => (($contact['archive']) ? L10n::t('Currently archived') : ''),
-                       '$pending' => (($contact['pending']) ? L10n::t('Awaiting connection acknowledge') : ''),
+                       '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
+                       '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
+                       '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
+                       '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
                        '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($contact['hidden'] == 1), L10n::t('Replies/likes to your public posts <strong>may</strong> still be visible')],
                        '$notify' => ['notify', L10n::t('Notification for new posts'), ($contact['notify_new_posts'] == 1), L10n::t('Send a notification of every new post of this contact')],
                        '$fetch_further_information' => $fetch_further_information,
@@ -723,6 +705,8 @@ function contacts_content(App $a, $update = 0)
                $sql_extra = " AND `blocked` = 0 ";
        }
 
+       $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
+
        $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
        $nets   = x($_GET, 'nets'  ) ? notags(trim($_GET['nets']))   : '';
 
@@ -809,7 +793,7 @@ function contacts_content(App $a, $update = 0)
                intval($_SESSION['uid'])
        );
        if (DBA::isResult($r)) {
-               $a->set_pager_total($r[0]['total']);
+               $a->setPagerTotal($r[0]['total']);
                $total = $r[0]['total'];
        }
 
@@ -972,7 +956,7 @@ function contact_conversations(App $a, $contact_id, $update)
                $profiledata = Contact::getDetailsByURL($contact["url"]);
 
                if (local_user()) {
-                       if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+                       if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                                $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
                        }
                }
@@ -996,7 +980,7 @@ function contact_posts(App $a, $contact_id)
                $profiledata = Contact::getDetailsByURL($contact["url"]);
 
                if (local_user()) {
-                       if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+                       if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                                $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
                        }
                }
@@ -1077,7 +1061,7 @@ function _contact_detail_for_template(array $rr)
  */
 function contact_actions($contact)
 {
-       $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
+       $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
        $contact_actions = [];
 
        // Provide friend suggestion only for Friendica contacts
@@ -1102,7 +1086,7 @@ function contact_actions($contact)
        }
 
        $contact_actions['block'] = [
-               'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
+               'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
                'url'   => 'contacts/' . $contact['id'] . '/block',
                'title' => L10n::t('Toggle Blocked status'),
                'sel'   => (intval($contact['blocked']) ? 'active' : ''),
@@ -1110,7 +1094,7 @@ function contact_actions($contact)
        ];
 
        $contact_actions['ignore'] = [
-               'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
+               'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
                'url'   => 'contacts/' . $contact['id'] . '/ignore',
                'title' => L10n::t('Toggle Ignored status'),
                'sel'   => (intval($contact['readonly']) ? 'active' : ''),
@@ -1119,7 +1103,7 @@ function contact_actions($contact)
 
        if ($contact['uid'] != 0) {
                $contact_actions['archive'] = [
-                       'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive') ),
+                       'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
                        'url'   => 'contacts/' . $contact['id'] . '/archive',
                        'title' => L10n::t('Toggle Archive status'),
                        'sel'   => (intval($contact['archive']) ? 'active' : ''),