]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact.php
Don't show deleted contacts, set new AP contacts as "pending" until they are accepted
[friendica.git] / src / Module / Contact.php
index db300759842ca84806d6627aac350d65df601218..245e5f0b226d00f8c0ed50c53c1dfd2dbf7e7f06 100644 (file)
@@ -22,6 +22,7 @@ use Friendica\Module\Login;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
 
 /**
  *  Manages and show Contacts and their content
@@ -39,11 +40,8 @@ class Contact extends BaseModule
                }
 
                $nets = defaults($_GET, 'nets', '');
-               if ($nets == 'all') {
-                       $nets = '';
-               }
 
-               if (!x($a->page, 'aside')) {
+               if (empty($a->page['aside'])) {
                        $a->page['aside'] = '';
                }
 
@@ -53,10 +51,10 @@ class Contact extends BaseModule
                        || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
                ) {
                        $contact_id = intval($a->argv[1]);
-                       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+                       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
 
                        if (!DBA::isResult($contact)) {
-                               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]);
+                               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0, 'deleted' => false]);
                        }
 
                        // Don't display contacts that are about to be deleted
@@ -77,18 +75,17 @@ class Contact extends BaseModule
                        $a->data['contact'] = $contact;
 
                        if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
-                               $networkname = format_network_name($contact['network'], $contact['url']);
+                               $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
                        } else {
-                               $networkname = '';
+                               $network_link = '';
                        }
 
-                       /// @TODO Add nice spaces
                        $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('vcard-widget.tpl'), [
-                               '$name'         => htmlentities($contact['name']),
+                               '$name'         => $contact['name'],
                                '$photo'        => $contact['photo'],
                                '$url'          => Model\Contact::MagicLink($contact['url']),
                                '$addr'         => defaults($contact, 'addr', ''),
-                               '$network_name' => $networkname,
+                               '$network_link' => $network_link,
                                '$network'      => L10n::t('Network:'),
                                '$account_type' => Model\Contact::getAccountType($contact)
                        ]);
@@ -138,7 +135,7 @@ class Contact extends BaseModule
 
                $contacts_id = $_POST['contact_batch'];
 
-               $stmt = DBA::select('contact', ['id', 'archive'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false]);
+               $stmt = DBA::select('contact', ['id', 'archive'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false, 'deleted' => false]);
                $orig_records = DBA::toArray($stmt);
 
                $count_actions = 0;
@@ -191,7 +188,7 @@ class Contact extends BaseModule
                        return;
                }
 
-               if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
+               if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) {
                        notice(L10n::t('Could not access contact record.') . EOL);
                        $a->internalRedirect('contact');
                        return; // NOTREACHED
@@ -201,7 +198,7 @@ class Contact extends BaseModule
 
                $profile_id = intval(defaults($_POST, 'profile-assign', 0));
                if ($profile_id) {
-                       if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
+                       if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user(), 'deleted' => false])) {
                                notice(L10n::t('Could not locate selected profile.') . EOL);
                                return;
                        }
@@ -213,14 +210,14 @@ class Contact extends BaseModule
 
                $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
 
-               $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
+               $ffi_keyword_blacklist = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
 
                $priority = intval(defaults($_POST, 'poll', 0));
                if ($priority > 5 || $priority < 0) {
                        $priority = 0;
                }
 
-               $info = escape_tags(trim($_POST['info']));
+               $info = Strings::escapeHtml(trim(defaults($_POST, 'info', '')));
 
                $r = DBA::update('contact', [
                        'profile-id' => $profile_id,
@@ -239,7 +236,7 @@ class Contact extends BaseModule
                        notice(L10n::t('Failed to update contact record.') . EOL);
                }
 
-               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
                if (DBA::isResult($contact)) {
                        $a->data['contact'] = $contact;
                }
@@ -251,7 +248,7 @@ class Contact extends BaseModule
 
        private static function updateContactFromPoll($contact_id)
        {
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+               $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
                if (!DBA::isResult($contact)) {
                        return;
                }
@@ -272,7 +269,7 @@ class Contact extends BaseModule
 
        private static function updateContactFromProbe($contact_id)
        {
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+               $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
                if (!DBA::isResult($contact)) {
                        return;
                }
@@ -303,7 +300,7 @@ class Contact extends BaseModule
                        }
                }
 
-               $fields['nurl'] = normalise_link($data['url']);
+               $fields['nurl'] = Strings::normaliseLink($data['url']);
 
                if (!empty($data['priority'])) {
                        $fields['priority'] = intval($data['priority']);
@@ -373,7 +370,7 @@ class Contact extends BaseModule
 
                        $cmd = $a->argv[2];
 
-                       $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
+                       $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
                        if (!DBA::isResult($orig_record)) {
                                notice(L10n::t('Could not access contact record.') . EOL);
                                $a->internalRedirect('contact');
@@ -513,7 +510,7 @@ class Contact extends BaseModule
                                $relation_text = '';
                        }
 
-                       $relation_text = sprintf($relation_text, htmlentities($contact['name']));
+                       $relation_text = sprintf($relation_text, $contact['name']);
 
                        $url = Model\Contact::magicLink($contact['url']);
                        if (strpos($url, 'redir/') === 0) {
@@ -569,12 +566,12 @@ class Contact extends BaseModule
                        /// @todo Only show the following link with DFRN when the remote version supports it
                        $follow = '';
                        $follow_text = '';
-                       if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
+                       if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
                                if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                                        $follow = $a->getBaseURL(true) . '/unfollow?url=' . urlencode($contact['url']);
                                        $follow_text = L10n::t('Disconnect/Unfollow');
                                }
-                       } else {
+                       } elseif(!$contact['pending']) {
                                $follow = $a->getBaseURL(true) . '/follow?url=' . urlencode($contact['url']);
                                $follow_text = L10n::t('Connect/Follow');
                        }
@@ -601,7 +598,7 @@ class Contact extends BaseModule
                                '$lbl_vis2'       => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
                                '$lbl_info1'      => $lbl_info1,
                                '$lbl_info2'      => L10n::t('Their personal note'),
-                               '$reason'         => trim(notags($contact['reason'])),
+                               '$reason'         => trim(Strings::escapeTags($contact['reason'])),
                                '$infedit'        => L10n::t('Edit contact notes'),
                                '$common_link'    => 'common/loc/' . local_user() . '/' . $contact['id'],
                                '$relation_text'  => $relation_text,
@@ -638,7 +635,7 @@ class Contact extends BaseModule
                                '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
                                '$ffi_keyword_blacklist' => ['ffi_keyword_blacklist', L10n::t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], L10n::t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
                                '$photo'          => $contact['photo'],
-                               '$name'           => htmlentities($contact['name']),
+                               '$name'           => $contact['name'],
                                '$dir_icon'       => $dir_icon,
                                '$sparkle'        => $sparkle,
                                '$url'            => $url,
@@ -694,8 +691,8 @@ class Contact extends BaseModule
 
                $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
 
-               $search = notags(trim(defaults($_GET, 'search', '')));
-               $nets   = notags(trim(defaults($_GET, 'nets'  , '')));
+               $search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
+               $nets   = Strings::escapeTags(trim(defaults($_GET, 'nets'  , '')));
 
                $tabs = [
                        [
@@ -754,6 +751,14 @@ class Contact extends BaseModule
                                'id'    => 'showhidden-tab',
                                'accesskey' => 'h',
                        ],
+                       [
+                               'label' => L10n::t('Groups'),
+                               'url'   => 'group',
+                               'sel'   => ($hidden) ? 'active' : '',
+                               'title' => L10n::t('Organize your contact groups'),
+                               'id'    => 'contactgroups-tab',
+                               'accesskey' => 'e',
+                       ],
                ];
 
                $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
@@ -765,7 +770,7 @@ class Contact extends BaseModule
                if ($search) {
                        $searching = true;
                        $search_hdr = $search;
-                       $search_txt = DBA::escape(protect_sprintf(preg_quote($search)));
+                       $search_txt = DBA::escape(Strings::protectSprintf(preg_quote($search)));
                        $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt'  OR nick REGEXP '$search_txt') ";
                }
 
@@ -773,6 +778,8 @@ class Contact extends BaseModule
                        $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
                }
 
+               $sql_extra .=  " AND NOT `deleted` ";
+
                $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
 
                $r = q("SELECT COUNT(*) AS `total` FROM `contact`
@@ -932,7 +939,7 @@ class Contact extends BaseModule
                        }
                }
 
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
+               $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
 
                if (!$update) {
                        $o .= self::getTabsHTML($a, $contact, 1);
@@ -956,7 +963,7 @@ class Contact extends BaseModule
 
        private static function getPostsHTML($a, $contact_id)
        {
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
+               $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
 
                $o = self::getTabsHTML($a, $contact, 2);
 
@@ -1024,14 +1031,14 @@ class Contact extends BaseModule
                        'alt_text'  => $alt_text,
                        'dir_icon'  => $dir_icon,
                        'thumb'     => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
-                       'name'      => htmlentities($rr['name']),
-                       'username'  => htmlentities($rr['name']),
+                       'name'      => $rr['name'],
+                       'username'  => $rr['name'],
                        'account_type' => Model\Contact::getAccountType($rr),
                        'sparkle'   => $sparkle,
                        'itemurl'   => defaults($rr, 'addr', $rr['url']),
                        'url'       => $url,
                        'network'   => ContactSelector::networkToName($rr['network'], $rr['url']),
-                       'nick'      => htmlentities($rr['nick']),
+                       'nick'      => $rr['nick'],
                ];
        }