]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact.php
bf0e3bfaf2a47e180f49ae33709bdf7f3eb81269
[friendica.git] / src / Module / Contact.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Content\ContactSelector;
26 use Friendica\Content\Nav;
27 use Friendica\Content\Pager;
28 use Friendica\Content\Text\BBCode;
29 use Friendica\Content\Widget;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Protocol;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Theme;
34 use Friendica\Core\Worker;
35 use Friendica\Database\DBA;
36 use Friendica\DI;
37 use Friendica\Model;
38 use Friendica\Model\User;
39 use Friendica\Module\Security\Login;
40 use Friendica\Network\HTTPException\BadRequestException;
41 use Friendica\Network\HTTPException\NotFoundException;
42 use Friendica\Util\DateTimeFormat;
43 use Friendica\Util\Strings;
44
45 /**
46  *  Manages and show Contacts and their content
47  */
48 class Contact extends BaseModule
49 {
50         const TAB_CONVERSATIONS = 1;
51         const TAB_POSTS = 2;
52         const TAB_PROFILE = 3;
53         const TAB_CONTACTS = 4;
54         const TAB_ADVANCED = 5;
55
56         private static function batchActions()
57         {
58                 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
59                         return;
60                 }
61
62                 $redirectUrl = $_POST['redirect_url'] ?? 'contact';
63
64                 self::checkFormSecurityTokenRedirectOnError($redirectUrl, 'contact_batch_actions');
65
66                 $orig_records = Model\Contact::selectToArray(['id', 'uid'], ['id' => $_POST['contact_batch'], 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
67
68                 $count_actions = 0;
69                 foreach ($orig_records as $orig_record) {
70                         $cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], local_user());
71                         if (empty($cdata)) {
72                                 continue;
73                         }
74
75                         if (!empty($_POST['contacts_batch_update']) && $cdata['user']) {
76                                 self::updateContactFromPoll($cdata['user']);
77                                 $count_actions++;
78                         }
79
80                         if (!empty($_POST['contacts_batch_block'])) {
81                                 self::toggleBlockContact($cdata['public']);
82                                 $count_actions++;
83                         }
84
85                         if (!empty($_POST['contacts_batch_ignore'])) {
86                                 self::toggleIgnoreContact($cdata['public']);
87                                 $count_actions++;
88                         }
89
90                         if (!empty($_POST['contacts_batch_drop']) && $cdata['user']
91                                 && self::dropContact($cdata['user'], local_user())
92                         ) {
93                                 $count_actions++;
94                         }
95                 }
96                 if ($count_actions > 0) {
97                         info(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions));
98                 }
99
100                 DI::baseUrl()->redirect($redirectUrl);
101         }
102
103         public static function post(array $parameters = [])
104         {
105                 if (!local_user()) {
106                         return;
107                 }
108
109                 // @TODO: Replace with parameter from router
110                 if (DI::args()->getArgv()[1] === 'batch') {
111                         self::batchActions();
112                         return;
113                 }
114
115                 // @TODO: Replace with parameter from router
116                 $contact_id = intval(DI::args()->getArgv()[1]);
117                 if (!$contact_id) {
118                         return;
119                 }
120
121                 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) {
122                         notice(DI::l10n()->t('Could not access contact record.'));
123                         DI::baseUrl()->redirect('contact');
124                         return; // NOTREACHED
125                 }
126
127                 Hook::callAll('contact_edit_post', $_POST);
128
129                 $hidden = !empty($_POST['hidden']);
130
131                 $notify = !empty($_POST['notify']);
132
133                 $fetch_further_information = intval($_POST['fetch_further_information'] ?? 0);
134
135                 $remote_self = $_POST['remote_self'] ?? false;
136
137                 $ffi_keyword_denylist = Strings::escapeHtml(trim($_POST['ffi_keyword_denylist'] ?? ''));
138
139                 $priority = intval($_POST['poll'] ?? 0);
140                 if ($priority > 5 || $priority < 0) {
141                         $priority = 0;
142                 }
143
144                 $info = Strings::escapeHtml(trim($_POST['info'] ?? ''));
145
146                 $r = Model\Contact::update([
147                         'priority'   => $priority,
148                         'info'       => $info,
149                         'hidden'     => $hidden,
150                         'notify_new_posts' => $notify,
151                         'fetch_further_information' => $fetch_further_information,
152                         'remote_self' => $remote_self,
153                         'ffi_keyword_denylist'     => $ffi_keyword_denylist],
154                         ['id' => $contact_id, 'uid' => local_user()]
155                 );
156
157                 if (!DBA::isResult($r)) {
158                         notice(DI::l10n()->t('Failed to update contact record.'));
159                 }
160                 return;
161         }
162
163         /* contact actions */
164
165         /**
166          * @param int $contact_id Id of contact with uid != 0
167          * @throws NotFoundException
168          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
169          * @throws \ImagickException
170          */
171         private static function updateContactFromPoll(int $contact_id)
172         {
173                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
174                 if (!DBA::isResult($contact)) {
175                         return;
176                 }
177
178                 if ($contact['network'] == Protocol::OSTATUS) {
179                         $result = Model\Contact::createFromProbeForUser($contact['uid'], $contact['url'], $contact['network']);
180
181                         if ($result['success']) {
182                                 Model\Contact::update(['subhub' => 1], ['id' => $contact_id]);
183                         }
184
185                         // pull feed and consume it, which should subscribe to the hub.
186                         Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
187                 } else {
188                         Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id);
189                 }
190         }
191
192         /**
193          * @param int $contact_id Id of the contact with uid != 0
194          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
195          * @throws \ImagickException
196          */
197         private static function updateContactFromProbe(int $contact_id)
198         {
199                 $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
200                 if (!DBA::isResult($contact)) {
201                         return;
202                 }
203
204                 // Update the entry in the contact table
205                 Model\Contact::updateFromProbe($contact_id);
206         }
207
208         /**
209          * Toggles the blocked status of a contact identified by id.
210          *
211          * @param int $contact_id Id of the contact with uid = 0
212          * @throws \Exception
213          */
214         private static function toggleBlockContact(int $contact_id)
215         {
216                 $blocked = !Model\Contact\User::isBlocked($contact_id, local_user());
217                 Model\Contact\User::setBlocked($contact_id, local_user(), $blocked);
218         }
219
220         /**
221          * Toggles the ignored status of a contact identified by id.
222          *
223          * @param int $contact_id Id of the contact with uid = 0
224          * @throws \Exception
225          */
226         private static function toggleIgnoreContact(int $contact_id)
227         {
228                 $ignored = !Model\Contact\User::isIgnored($contact_id, local_user());
229                 Model\Contact\User::setIgnored($contact_id, local_user(), $ignored);
230         }
231
232         /**
233          * @param int $contact_id Id for contact with uid != 0
234          * @param int $uid        Id for user we want to drop the contact for
235          * @return bool
236          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
237          * @throws \ImagickException
238          */
239         private static function dropContact(int $contact_id, int $uid): bool
240         {
241                 $contact = Model\Contact::getContactForUser($contact_id, $uid);
242                 if (!DBA::isResult($contact)) {
243                         return false;
244                 }
245
246                 $owner = Model\User::getOwnerDataById($uid);
247                 if (!DBA::isResult($owner)) {
248                         return false;
249                 }
250
251                 Model\Contact::terminateFriendship($owner, $contact, true);
252                 Model\Contact::remove($contact['id']);
253
254                 return true;
255         }
256
257         public static function content(array $parameters = [], $update = 0)
258         {
259                 if (!local_user()) {
260                         return Login::form($_SERVER['REQUEST_URI']);
261                 }
262
263                 $a = DI::app();
264
265                 $search = Strings::escapeTags(trim($_GET['search'] ?? ''));
266                 $nets   = Strings::escapeTags(trim($_GET['nets']   ?? ''));
267                 $rel    = Strings::escapeTags(trim($_GET['rel']    ?? ''));
268                 $group  = Strings::escapeTags(trim($_GET['group']  ?? ''));
269
270                 $accounttype = $_GET['accounttype'] ?? '';
271                 $accounttypeid = User::getAccountTypeByString($accounttype);
272
273                 $page = DI::page();
274
275                 $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
276                 $page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
277                 $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
278                 $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
279
280                 $contact = null;
281                 // @TODO: Replace with parameter from router
282                 if (DI::args()->getArgc() == 2 && intval(DI::args()->getArgv()[1])
283                         || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])
284                 ) {
285                         $contact_id = intval(DI::args()->getArgv()[1]);
286
287                         // Ensure to use the user contact when the public contact was provided
288                         $data = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
289                         if (!empty($data['user']) && ($contact_id == $data['public'])) {
290                                 $contact_id = $data['user'];
291                         }
292
293                         if (!empty($data)) {
294                                 $contact = DBA::selectFirst('contact', [], [
295                                         'id'      => $contact_id,
296                                         'uid'     => [0, local_user()],
297                                         'deleted' => false
298                                 ]);
299
300                                 // Don't display contacts that are about to be deleted
301                                 if (DBA::isResult($contact) && !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM) {
302                                         $contact = false;
303                                 }
304                         }
305                 }
306
307                 if (DBA::isResult($contact)) {
308                         if ($contact['self']) {
309                                 // @TODO: Replace with parameter from router
310                                 if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) {
311                                         DI::baseUrl()->redirect('profile/' . $contact['nick']);
312                                 } else {
313                                         DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile');
314                                 }
315                         }
316
317                         $vcard_widget = Widget\VCard::getHTML($contact);
318
319                         $findpeople_widget = '';
320                         $follow_widget = '';
321                         $account_widget = '';
322                         $networks_widget = '';
323                         $rel_widget = '';
324
325                         if ($contact['uid'] != 0) {
326                                 $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
327                         } else {
328                                 $groups_widget = '';
329                         }
330                 } else {
331                         $vcard_widget = '';
332                         $findpeople_widget = Widget::findPeople();
333                         if (isset($_GET['add'])) {
334                                 $follow_widget = Widget::follow($_GET['add']);
335                         } else {
336                                 $follow_widget = Widget::follow();
337                         }
338
339                         $account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
340                         $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
341                         $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
342                         $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group);
343                 }
344
345                 DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $account_widget . $groups_widget . $networks_widget . $rel_widget;
346
347                 $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
348                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
349                         '$baseurl' => DI::baseUrl()->get(true),
350                 ]);
351
352                 $o = '';
353                 Nav::setSelected('contact');
354
355                 if (!local_user()) {
356                         notice(DI::l10n()->t('Permission denied.'));
357                         return Login::form();
358                 }
359
360                 if (DI::args()->getArgc() == 3) {
361                         $contact_id = intval(DI::args()->getArgv()[1]);
362                         if (!$contact_id) {
363                                 throw new BadRequestException();
364                         }
365
366                         // @TODO: Replace with parameter from router
367                         $cmd = DI::args()->getArgv()[2];
368
369                         $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
370                         if (!DBA::isResult($orig_record)) {
371                                 throw new NotFoundException(DI::l10n()->t('Contact not found'));
372                         }
373
374                         if ($cmd === 'posts') {
375                                 return self::getPostsHTML($a, $contact_id);
376                         }
377
378                         if ($cmd === 'conversations') {
379                                 return self::getConversationsHMTL($a, $contact_id, $update);
380                         }
381
382                         self::checkFormSecurityTokenRedirectOnError('contact/' . $contact_id, 'contact_action', 't');
383
384                         $cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], local_user());
385                         if (empty($cdata)) {
386                                 throw new NotFoundException(DI::l10n()->t('Contact not found'));
387                         }
388
389                         if ($cmd === 'update' && $cdata['user']) {
390                                 self::updateContactFromPoll($cdata['user']);
391                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
392                                 // NOTREACHED
393                         }
394
395                         if ($cmd === 'updateprofile' && $cdata['user']) {
396                                 self::updateContactFromProbe($cdata['user']);
397                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
398                                 // NOTREACHED
399                         }
400
401                         if ($cmd === 'block') {
402                                 if (public_contact() === $cdata['public']) {
403                                         throw new BadRequestException(DI::l10n()->t('You can\'t block yourself'));
404                                 }
405
406                                 self::toggleBlockContact($cdata['public']);
407
408                                 $blocked = Model\Contact\User::isBlocked($contact_id, local_user());
409                                 info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')));
410
411                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
412                                 // NOTREACHED
413                         }
414
415                         if ($cmd === 'ignore') {
416                                 if (public_contact() === $cdata['public']) {
417                                         throw new BadRequestException(DI::l10n()->t('You can\'t ignore yourself'));
418                                 }
419
420                                 self::toggleIgnoreContact($cdata['public']);
421
422                                 $ignored = Model\Contact\User::isIgnored($cdata['public'], local_user());
423                                 info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')));
424
425                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
426                                 // NOTREACHED
427                         }
428
429                         if ($cmd === 'drop' && $cdata['user']) {
430                                 // Check if we should do HTML-based delete confirmation
431                                 if (!empty($_REQUEST['confirm'])) {
432                                         DI::page()['aside'] = '';
433
434                                         return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
435                                                 '$header' => DI::l10n()->t('Drop contact'),
436                                                 '$contact' => self::getContactTemplateVars($orig_record),
437                                                 '$method' => 'get',
438                                                 '$message' => DI::l10n()->t('Do you really want to delete this contact?'),
439                                                 '$confirm' => DI::l10n()->t('Yes'),
440                                                 '$confirm_url' => DI::args()->getCommand(),
441                                                 '$confirm_name' => 't',
442                                                 '$confirm_value' => BaseModule::getFormSecurityToken('contact_action'),
443                                                 '$cancel' => DI::l10n()->t('Cancel'),
444                                         ]);
445                                 }
446                                 // Now check how the user responded to the confirmation query
447                                 if (!empty($_REQUEST['canceled'])) {
448                                         DI::baseUrl()->redirect('contact');
449                                 }
450
451                                 if (self::dropContact($cdata['user'], local_user())) {
452                                         info(DI::l10n()->t('Contact has been removed.'));
453                                 }
454
455                                 DI::baseUrl()->redirect('contact');
456                                 // NOTREACHED
457                         }
458                 }
459
460                 $_SESSION['return_path'] = DI::args()->getQueryString();
461
462                 if (!empty($contact)) {
463                         DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
464                                 '$baseurl' => DI::baseUrl()->get(true),
465                         ]);
466
467                         $contact['blocked']  = Model\Contact\User::isBlocked($contact['id'], local_user());
468                         $contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], local_user());
469
470                         $relation_text = '';
471                         switch ($contact['rel']) {
472                                 case Model\Contact::FRIEND:
473                                         $relation_text = DI::l10n()->t('You are mutual friends with %s');
474                                         break;
475
476                                 case Model\Contact::FOLLOWER;
477                                         $relation_text = DI::l10n()->t('You are sharing with %s');
478                                         break;
479
480                                 case Model\Contact::SHARING;
481                                         $relation_text = DI::l10n()->t('%s is sharing with you');
482                                         break;
483
484                                 default:
485                                         break;
486                         }
487
488                         if ($contact['uid'] == 0) {
489                                 $relation_text = '';
490                         }
491
492                         if (!in_array($contact['network'], array_merge(Protocol::FEDERATED, [Protocol::TWITTER]))) {
493                                 $relation_text = '';
494                         }
495
496                         $relation_text = sprintf($relation_text, $contact['name']);
497
498                         $url = Model\Contact::magicLinkByContact($contact);
499                         if (strpos($url, 'redir/') === 0) {
500                                 $sparkle = ' class="sparkle" ';
501                         } else {
502                                 $sparkle = '';
503                         }
504
505                         $insecure = DI::l10n()->t('Private communications are not available for this contact.');
506
507                         $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? DI::l10n()->t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
508
509                         if ($contact['last-update'] > DBA::NULL_DATETIME) {
510                                 $last_update .= ' ' . ($contact['failed'] ? DI::l10n()->t('(Update was not successful)') : DI::l10n()->t('(Update was successful)'));
511                         }
512                         $lblsuggest = (($contact['network'] === Protocol::DFRN) ? DI::l10n()->t('Suggest friends') : '');
513
514                         $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
515
516                         $nettype = DI::l10n()->t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']));
517
518                         // tabs
519                         $tab_str = self::getTabsHTML($contact, self::TAB_PROFILE);
520
521                         $lost_contact = (($contact['archive'] && $contact['term-date'] > DBA::NULL_DATETIME && $contact['term-date'] < DateTimeFormat::utcNow()) ? DI::l10n()->t('Communications lost with this contact!') : '');
522
523                         $fetch_further_information = null;
524                         if ($contact['network'] == Protocol::FEED) {
525                                 $fetch_further_information = [
526                                         'fetch_further_information',
527                                         DI::l10n()->t('Fetch further information for feeds'),
528                                         $contact['fetch_further_information'],
529                                         DI::l10n()->t('Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn\'t contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags.'),
530                                         [
531                                                 '0' => DI::l10n()->t('Disabled'),
532                                                 '1' => DI::l10n()->t('Fetch information'),
533                                                 '3' => DI::l10n()->t('Fetch keywords'),
534                                                 '2' => DI::l10n()->t('Fetch information and keywords')
535                                         ]
536                                 ];
537                         }
538
539                         // Disable remote self for everything except feeds.
540                         // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
541                         // Problem is, you couldn't reply to both networks.
542                         $allow_remote_self = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
543                                 && DI::config()->get('system', 'allow_users_remote_self');
544
545                         if ($contact['network'] == Protocol::FEED) {
546                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
547                                         Model\Contact::MIRROR_FORWARDED => DI::l10n()->t('Mirror as forwarded posting'),
548                                         Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
549                         } elseif (in_array($contact['network'], [Protocol::ACTIVITYPUB])) {
550                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
551                                 Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
552                         } elseif (in_array($contact['network'], [Protocol::DFRN])) {
553                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
554                                 Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting'),
555                                 Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
556                         } else {
557                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
558                                         Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
559                         }
560
561                         $poll_interval = null;
562                         if ((($contact['network'] == Protocol::FEED) && !DI::config()->get('system', 'adjust_poll_frequency')) || ($contact['network'] == Protocol::MAIL)) {
563                                 $poll_interval = ContactSelector::pollInterval($contact['priority'], !$poll_enabled);
564                         }
565
566                         // Load contactact related actions like hide, suggest, delete and others
567                         $contact_actions = self::getContactActions($contact);
568
569                         if ($contact['uid'] != 0) {
570                                 $lbl_info1 = DI::l10n()->t('Contact Information / Notes');
571                                 $contact_settings_label = DI::l10n()->t('Contact Settings');
572                         } else {
573                                 $lbl_info1 = null;
574                                 $contact_settings_label = null;
575                         }
576
577                         $tpl = Renderer::getMarkupTemplate('contact_edit.tpl');
578                         $o .= Renderer::replaceMacros($tpl, [
579                                 '$header'         => DI::l10n()->t('Contact'),
580                                 '$tab_str'        => $tab_str,
581                                 '$submit'         => DI::l10n()->t('Submit'),
582                                 '$lbl_info1'      => $lbl_info1,
583                                 '$lbl_info2'      => DI::l10n()->t('Their personal note'),
584                                 '$reason'         => trim(Strings::escapeTags($contact['reason'])),
585                                 '$infedit'        => DI::l10n()->t('Edit contact notes'),
586                                 '$common_link'    => 'contact/' . $contact['id'] . '/contacts/common',
587                                 '$relation_text'  => $relation_text,
588                                 '$visit'          => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
589                                 '$blockunblock'   => DI::l10n()->t('Block/Unblock contact'),
590                                 '$ignorecont'     => DI::l10n()->t('Ignore contact'),
591                                 '$lblrecent'      => DI::l10n()->t('View conversations'),
592                                 '$lblsuggest'     => $lblsuggest,
593                                 '$nettype'        => $nettype,
594                                 '$poll_interval'  => $poll_interval,
595                                 '$poll_enabled'   => $poll_enabled,
596                                 '$lastupdtext'    => DI::l10n()->t('Last update:'),
597                                 '$lost_contact'   => $lost_contact,
598                                 '$updpub'         => DI::l10n()->t('Update public posts'),
599                                 '$last_update'    => $last_update,
600                                 '$udnow'          => DI::l10n()->t('Update now'),
601                                 '$contact_id'     => $contact['id'],
602                                 '$block_text'     => ($contact['blocked'] ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')),
603                                 '$ignore_text'    => ($contact['readonly'] ? DI::l10n()->t('Unignore') : DI::l10n()->t('Ignore')),
604                                 '$insecure'       => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
605                                 '$info'           => $contact['info'],
606                                 '$cinfo'          => ['info', '', $contact['info'], ''],
607                                 '$blocked'        => ($contact['blocked'] ? DI::l10n()->t('Currently blocked') : ''),
608                                 '$ignored'        => ($contact['readonly'] ? DI::l10n()->t('Currently ignored') : ''),
609                                 '$archived'       => ($contact['archive'] ? DI::l10n()->t('Currently archived') : ''),
610                                 '$pending'        => ($contact['pending'] ? DI::l10n()->t('Awaiting connection acknowledge') : ''),
611                                 '$hidden'         => ['hidden', DI::l10n()->t('Hide this contact from others'), ($contact['hidden'] == 1), DI::l10n()->t('Replies/likes to your public posts <strong>may</strong> still be visible')],
612                                 '$notify'         => ['notify', DI::l10n()->t('Notification for new posts'), ($contact['notify_new_posts'] == 1), DI::l10n()->t('Send a notification of every new post of this contact')],
613                                 '$fetch_further_information' => $fetch_further_information,
614                                 '$ffi_keyword_denylist' => ['ffi_keyword_denylist', DI::l10n()->t('Keyword Deny List'), $contact['ffi_keyword_denylist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
615                                 '$photo'          => Model\Contact::getPhoto($contact),
616                                 '$name'           => $contact['name'],
617                                 '$sparkle'        => $sparkle,
618                                 '$url'            => $url,
619                                 '$profileurllabel'=> DI::l10n()->t('Profile URL'),
620                                 '$profileurl'     => $contact['url'],
621                                 '$account_type'   => Model\Contact::getAccountType($contact),
622                                 '$location'       => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
623                                 '$location_label' => DI::l10n()->t('Location:'),
624                                 '$xmpp'           => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
625                                 '$xmpp_label'     => DI::l10n()->t('XMPP:'),
626                                 '$matrix'         => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['matrix']),
627                                 '$matrix_label'   => DI::l10n()->t('Matrix:'),
628                                 '$about'          => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'], BBCode::EXTERNAL),
629                                 '$about_label'    => DI::l10n()->t('About:'),
630                                 '$keywords'       => $contact['keywords'],
631                                 '$keywords_label' => DI::l10n()->t('Tags:'),
632                                 '$contact_action_button' => DI::l10n()->t('Actions'),
633                                 '$contact_actions'=> $contact_actions,
634                                 '$contact_status' => DI::l10n()->t('Status'),
635                                 '$contact_settings_label' => $contact_settings_label,
636                                 '$contact_profile_label' => DI::l10n()->t('Profile'),
637                                 '$allow_remote_self' => $allow_remote_self,
638                                 '$remote_self'       => ['remote_self',
639                                         DI::l10n()->t('Mirror postings from this contact'),
640                                         $contact['remote_self'],
641                                         DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
642                                         $remote_self_options
643                                 ],
644                         ]);
645
646                         $arr = ['contact' => $contact, 'output' => $o];
647
648                         Hook::callAll('contact_edit', $arr);
649
650                         return $arr['output'];
651                 }
652
653                 $sql_values = [local_user()];
654
655                 // @TODO: Replace with parameter from router
656                 $type = DI::args()->getArgv()[1] ?? '';
657
658                 switch ($type) {
659                         case 'blocked':
660                                 $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`blocked`)";
661                                 // This makes the query look for contact.uid = 0
662                                 array_unshift($sql_values, 0);
663                                 break;
664                         case 'hidden':
665                                 $sql_extra = " AND `hidden` AND NOT `blocked` AND NOT `pending`";
666                                 break;
667                         case 'ignored':
668                                 $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`ignored`)";
669                                 // This makes the query look for contact.uid = 0
670                                 array_unshift($sql_values, 0);
671                                 break;
672                         case 'archived':
673                                 $sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
674                                 break;
675                         case 'pending':
676                                 $sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
677                                         OR EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id` AND NOT `ignore`))";
678                                 $sql_values[] = Model\Contact::SHARING;
679                                 break;
680                         default:
681                                 $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`";
682                                 break;
683                 }
684
685                 if (isset($accounttypeid)) {
686                         $sql_extra .= " AND `contact-type` = ?";
687                         $sql_values[] = $accounttypeid;
688                 }
689
690                 $searching = false;
691                 $search_hdr = null;
692                 if ($search) {
693                         $searching = true;
694                         $search_hdr = $search;
695                         $search_txt = preg_quote($search);
696                         $sql_extra .= " AND (name REGEXP ? OR url REGEXP ? OR nick REGEXP ?)";
697                         $sql_values[] = $search_txt;
698                         $sql_values[] = $search_txt;
699                         $sql_values[] = $search_txt;
700                 }
701
702                 if ($nets) {
703                         $sql_extra .= " AND network = ? ";
704                         $sql_values[] = $nets;
705                 }
706
707                 switch ($rel) {
708                         case 'followers':
709                                 $sql_extra .= " AND `rel` IN (?, ?)";
710                                 $sql_values[] = Model\Contact::FOLLOWER;
711                                 $sql_values[] = Model\Contact::FRIEND;
712                                 break;
713                         case 'following':
714                                 $sql_extra .= " AND `rel` IN (?, ?)";
715                                 $sql_values[] = Model\Contact::SHARING;
716                                 $sql_values[] = Model\Contact::FRIEND;
717                                 break;
718                         case 'mutuals':
719                                 $sql_extra .= " AND `rel` = ?";
720                                 $sql_values[] = Model\Contact::FRIEND;
721                                 break;
722                 }
723
724                 if ($group) {
725                         $sql_extra = " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)";
726                         $sql_values[] = $group;
727                 }
728
729                 $total = 0;
730                 $stmt = DBA::p("SELECT COUNT(*) AS `total`
731                         FROM `contact`
732                         WHERE `uid` = ?
733                         AND `self` = 0
734                         AND NOT `deleted`
735                         $sql_extra
736                         " . Widget::unavailableNetworks(),
737                         $sql_values
738                 );
739                 if (DBA::isResult($stmt)) {
740                         $total = DBA::fetch($stmt)['total'];
741                 }
742                 DBA::close($stmt);
743
744                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
745
746                 $sql_values[] = $pager->getStart();
747                 $sql_values[] = $pager->getItemsPerPage();
748
749                 $contacts = [];
750
751                 $stmt = DBA::p("SELECT *
752                         FROM `contact`
753                         WHERE `uid` = ?
754                         AND `self` = 0
755                         AND NOT `deleted`
756                         $sql_extra
757                         ORDER BY `name` ASC
758                         LIMIT ?, ?",
759                         $sql_values
760                 );
761                 while ($contact = DBA::fetch($stmt)) {
762                         $contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], local_user());
763                         $contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], local_user());
764                         $contacts[] = self::getContactTemplateVars($contact);
765                 }
766                 DBA::close($stmt);
767
768                 $tabs = [
769                         [
770                                 'label' => DI::l10n()->t('All Contacts'),
771                                 'url'   => 'contact',
772                                 'sel'   => !$type ? 'active' : '',
773                                 'title' => DI::l10n()->t('Show all contacts'),
774                                 'id'    => 'showall-tab',
775                                 'accesskey' => 'l',
776                         ],
777                         [
778                                 'label' => DI::l10n()->t('Pending'),
779                                 'url'   => 'contact/pending',
780                                 'sel'   => $type == 'pending' ? 'active' : '',
781                                 'title' => DI::l10n()->t('Only show pending contacts'),
782                                 'id'    => 'showpending-tab',
783                                 'accesskey' => 'p',
784                         ],
785                         [
786                                 'label' => DI::l10n()->t('Blocked'),
787                                 'url'   => 'contact/blocked',
788                                 'sel'   => $type == 'blocked' ? 'active' : '',
789                                 'title' => DI::l10n()->t('Only show blocked contacts'),
790                                 'id'    => 'showblocked-tab',
791                                 'accesskey' => 'b',
792                         ],
793                         [
794                                 'label' => DI::l10n()->t('Ignored'),
795                                 'url'   => 'contact/ignored',
796                                 'sel'   => $type == 'ignored' ? 'active' : '',
797                                 'title' => DI::l10n()->t('Only show ignored contacts'),
798                                 'id'    => 'showignored-tab',
799                                 'accesskey' => 'i',
800                         ],
801                         [
802                                 'label' => DI::l10n()->t('Archived'),
803                                 'url'   => 'contact/archived',
804                                 'sel'   => $type == 'archived' ? 'active' : '',
805                                 'title' => DI::l10n()->t('Only show archived contacts'),
806                                 'id'    => 'showarchived-tab',
807                                 'accesskey' => 'y',
808                         ],
809                         [
810                                 'label' => DI::l10n()->t('Hidden'),
811                                 'url'   => 'contact/hidden',
812                                 'sel'   => $type == 'hidden' ? 'active' : '',
813                                 'title' => DI::l10n()->t('Only show hidden contacts'),
814                                 'id'    => 'showhidden-tab',
815                                 'accesskey' => 'h',
816                         ],
817                         [
818                                 'label' => DI::l10n()->t('Groups'),
819                                 'url'   => 'group',
820                                 'sel'   => '',
821                                 'title' => DI::l10n()->t('Organize your contact groups'),
822                                 'id'    => 'contactgroups-tab',
823                                 'accesskey' => 'e',
824                         ],
825                 ];
826
827                 $tabs_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
828                 $tabs_html = Renderer::replaceMacros($tabs_tpl, ['$tabs' => $tabs]);
829
830                 switch ($rel) {
831                         case 'followers': $header = DI::l10n()->t('Followers'); break;
832                         case 'following': $header = DI::l10n()->t('Following'); break;
833                         case 'mutuals':   $header = DI::l10n()->t('Mutual friends'); break;
834                         default:          $header = DI::l10n()->t('Contacts');
835                 }
836
837                 switch ($type) {
838                         case 'pending':  $header .= ' - ' . DI::l10n()->t('Pending'); break;
839                         case 'blocked':  $header .= ' - ' . DI::l10n()->t('Blocked'); break;
840                         case 'hidden':   $header .= ' - ' . DI::l10n()->t('Hidden'); break;
841                         case 'ignored':  $header .= ' - ' . DI::l10n()->t('Ignored'); break;
842                         case 'archived': $header .= ' - ' . DI::l10n()->t('Archived'); break;
843                 }
844
845                 $header .= $nets ? ' - ' . ContactSelector::networkToName($nets) : '';
846
847                 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
848                 $o .= Renderer::replaceMacros($tpl, [
849                         '$header'     => $header,
850                         '$tabs'       => $tabs_html,
851                         '$total'      => $total,
852                         '$search'     => $search_hdr,
853                         '$desc'       => DI::l10n()->t('Search your contacts'),
854                         '$finding'    => $searching ? DI::l10n()->t('Results for: %s', $search) : '',
855                         '$submit'     => DI::l10n()->t('Find'),
856                         '$cmd'        => DI::args()->getCommand(),
857                         '$contacts'   => $contacts,
858                         '$form_security_token'  => BaseModule::getFormSecurityToken('contact_batch_actions'),
859                         '$contact_drop_confirm' => DI::l10n()->t('Do you really want to delete this contact?'),
860                         'multiselect' => 1,
861                         '$batch_actions' => [
862                                 'contacts_batch_update'  => DI::l10n()->t('Update'),
863                                 'contacts_batch_block'   => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
864                                 'contacts_batch_ignore'  => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
865                                 'contacts_batch_drop'    => DI::l10n()->t('Delete'),
866                         ],
867                         '$h_batch_actions' => DI::l10n()->t('Batch Actions'),
868                         '$paginate'   => $pager->renderFull($total),
869                 ]);
870
871                 return $o;
872         }
873
874         /**
875          * List of pages for the Contact TabBar
876          *
877          * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
878          *
879          * @param array $contact    The contact array
880          * @param int   $active_tab 1 if tab should be marked as active
881          *
882          * @return string HTML string of the contact page tabs buttons.
883          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
884          * @throws \ImagickException
885          */
886         public static function getTabsHTML(array $contact, int $active_tab)
887         {
888                 $cid = $pcid = $contact['id'];
889                 $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user());
890                 if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
891                         $cid = $data['user'];
892                 } elseif (!empty($data['public'])) {
893                         $pcid = $data['public'];
894                 }
895
896                 // tabs
897                 $tabs = [
898                         [
899                                 'label' => DI::l10n()->t('Status'),
900                                 'url'   => 'contact/' . $pcid . '/conversations',
901                                 'sel'   => (($active_tab == self::TAB_CONVERSATIONS) ? 'active' : ''),
902                                 'title' => DI::l10n()->t('Conversations started by this contact'),
903                                 'id'    => 'status-tab',
904                                 'accesskey' => 'm',
905                         ],
906                         [
907                                 'label' => DI::l10n()->t('Posts and Comments'),
908                                 'url'   => 'contact/' . $pcid . '/posts',
909                                 'sel'   => (($active_tab == self::TAB_POSTS) ? 'active' : ''),
910                                 'title' => DI::l10n()->t('Status Messages and Posts'),
911                                 'id'    => 'posts-tab',
912                                 'accesskey' => 'p',
913                         ],
914                         [
915                                 'label' => DI::l10n()->t('Profile'),
916                                 'url'   => 'contact/' . $cid,
917                                 'sel'   => (($active_tab == self::TAB_PROFILE) ? 'active' : ''),
918                                 'title' => DI::l10n()->t('Profile Details'),
919                                 'id'    => 'profile-tab',
920                                 'accesskey' => 'o',
921                         ],
922                         ['label' => DI::l10n()->t('Contacts'),
923                                 'url'   => 'contact/' . $pcid . '/contacts',
924                                 'sel'   => (($active_tab == self::TAB_CONTACTS) ? 'active' : ''),
925                                 'title' => DI::l10n()->t('View all known contacts'),
926                                 'id'    => 'contacts-tab',
927                                 'accesskey' => 't'
928                         ],
929                 ];
930
931                 if (!empty($contact['network']) && in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && ($cid != $pcid)) {
932                         $tabs[] = ['label' => DI::l10n()->t('Advanced'),
933                                 'url'   => 'contact/' . $cid . '/advanced/',
934                                 'sel'   => (($active_tab == self::TAB_ADVANCED) ? 'active' : ''),
935                                 'title' => DI::l10n()->t('Advanced Contact Settings'),
936                                 'id'    => 'advanced-tab',
937                                 'accesskey' => 'r'
938                         ];
939                 }
940
941                 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
942                 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
943
944                 return $tab_str;
945         }
946
947         public static function getConversationsHMTL($a, $contact_id, $update, $parent = 0)
948         {
949                 $o = '';
950
951                 if (!$update) {
952                         // We need the editor here to be able to reshare an item.
953                         if (local_user()) {
954                                 $o = DI::conversation()->statusEditor([], 0, true);
955                         }
956                 }
957
958                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
959
960                 if (!$update) {
961                         $o .= self::getTabsHTML($contact, self::TAB_CONVERSATIONS);
962                 }
963
964                 if (DBA::isResult($contact)) {
965                         if (!$update) {
966                                 $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
967                                 DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
968                         } else {
969                                 DI::page()['aside'] = '';
970                         }
971
972                         if ($contact['uid'] == 0) {
973                                 $o .= Model\Contact::getPostsFromId($contact['id'], true, $update, $parent);
974                         } else {
975                                 $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update, $parent);
976                         }
977                 }
978
979                 return $o;
980         }
981
982         private static function getPostsHTML($a, $contact_id)
983         {
984                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
985
986                 $o = self::getTabsHTML($contact, self::TAB_POSTS);
987
988                 if (DBA::isResult($contact)) {
989                         $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
990
991                         if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
992                                 $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
993                         }
994
995                         DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
996
997                         if ($contact['uid'] == 0) {
998                                 $o .= Model\Contact::getPostsFromId($contact['id']);
999                         } else {
1000                                 $o .= Model\Contact::getPostsFromUrl($contact['url']);
1001                         }
1002                 }
1003
1004                 return $o;
1005         }
1006
1007         /**
1008          * Return the fields for the contact template
1009          *
1010          * @param array $contact Contact array
1011          * @return array Template fields
1012          */
1013         public static function getContactTemplateVars(array $contact)
1014         {
1015                 $alt_text = '';
1016
1017                 if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && local_user()) {
1018                         $personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], local_user());
1019                         if (!empty($personal)) {
1020                                 $contact['uid'] = $personal['uid'];
1021                                 $contact['rel'] = $personal['rel'];
1022                                 $contact['self'] = $personal['self'];
1023                         }
1024                 }
1025
1026                 if (!empty($contact['uid']) && !empty($contact['rel']) && local_user() == $contact['uid']) {
1027                         switch ($contact['rel']) {
1028                                 case Model\Contact::FRIEND:
1029                                         $alt_text = DI::l10n()->t('Mutual Friendship');
1030                                         break;
1031
1032                                 case Model\Contact::FOLLOWER;
1033                                         $alt_text = DI::l10n()->t('is a fan of yours');
1034                                         break;
1035
1036                                 case Model\Contact::SHARING;
1037                                         $alt_text = DI::l10n()->t('you are a fan of');
1038                                         break;
1039
1040                                 default:
1041                                         break;
1042                         }
1043                 }
1044
1045                 $url = Model\Contact::magicLinkByContact($contact);
1046
1047                 if (strpos($url, 'redir/') === 0) {
1048                         $sparkle = ' class="sparkle" ';
1049                 } else {
1050                         $sparkle = '';
1051                 }
1052
1053                 if ($contact['pending']) {
1054                         if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
1055                                 $alt_text = DI::l10n()->t('Pending outgoing contact request');
1056                         } else {
1057                                 $alt_text = DI::l10n()->t('Pending incoming contact request');
1058                         }
1059                 }
1060
1061                 if ($contact['self']) {
1062                         $alt_text = DI::l10n()->t('This is you');
1063                         $url = $contact['url'];
1064                         $sparkle = '';
1065                 }
1066
1067                 return [
1068                         'id'           => $contact['id'],
1069                         'url'          => $url,
1070                         'img_hover'    => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
1071                         'photo_menu'   => Model\Contact::photoMenu($contact),
1072                         'thumb'        => Model\Contact::getThumb($contact, true),
1073                         'alt_text'     => $alt_text,
1074                         'name'         => $contact['name'],
1075                         'nick'         => $contact['nick'],
1076                         'details'      => $contact['location'],
1077                         'tags'         => $contact['keywords'],
1078                         'about'        => $contact['about'],
1079                         'account_type' => Model\Contact::getAccountType($contact),
1080                         'sparkle'      => $sparkle,
1081                         'itemurl'      => ($contact['addr'] ?? '') ?: $contact['url'],
1082                         'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
1083                 ];
1084         }
1085
1086         /**
1087          * Gives a array with actions which can performed to a given contact
1088          *
1089          * This includes actions like e.g. 'block', 'hide', 'delete' and others
1090          *
1091          * @param array $contact Data about the Contact
1092          * @return array with contact related actions
1093          */
1094         private static function getContactActions($contact)
1095         {
1096                 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1097                 $contact_actions = [];
1098
1099                 $formSecurityToken = self::getFormSecurityToken('contact_action');
1100
1101                 // Provide friend suggestion only for Friendica contacts
1102                 if ($contact['network'] === Protocol::DFRN) {
1103                         $contact_actions['suggest'] = [
1104                                 'label' => DI::l10n()->t('Suggest friends'),
1105                                 'url'   => 'fsuggest/' . $contact['id'],
1106                                 'title' => '',
1107                                 'sel'   => '',
1108                                 'id'    => 'suggest',
1109                         ];
1110                 }
1111
1112                 if ($poll_enabled) {
1113                         $contact_actions['update'] = [
1114                                 'label' => DI::l10n()->t('Update now'),
1115                                 'url'   => 'contact/' . $contact['id'] . '/update?t=' . $formSecurityToken,
1116                                 'title' => '',
1117                                 'sel'   => '',
1118                                 'id'    => 'update',
1119                         ];
1120                 }
1121
1122                 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
1123                         $contact_actions['updateprofile'] = [
1124                                 'label' => DI::l10n()->t('Refetch contact data'),
1125                                 'url'   => 'contact/' . $contact['id'] . '/updateprofile?t=' . $formSecurityToken,
1126                                 'title' => '',
1127                                 'sel'   => '',
1128                                 'id'    => 'updateprofile',
1129                         ];
1130                 }
1131
1132                 $contact_actions['block'] = [
1133                         'label' => (intval($contact['blocked']) ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')),
1134                         'url'   => 'contact/' . $contact['id'] . '/block?t=' . $formSecurityToken,
1135                         'title' => DI::l10n()->t('Toggle Blocked status'),
1136                         'sel'   => (intval($contact['blocked']) ? 'active' : ''),
1137                         'id'    => 'toggle-block',
1138                 ];
1139
1140                 $contact_actions['ignore'] = [
1141                         'label' => (intval($contact['readonly']) ? DI::l10n()->t('Unignore') : DI::l10n()->t('Ignore')),
1142                         'url'   => 'contact/' . $contact['id'] . '/ignore?t=' . $formSecurityToken,
1143                         'title' => DI::l10n()->t('Toggle Ignored status'),
1144                         'sel'   => (intval($contact['readonly']) ? 'active' : ''),
1145                         'id'    => 'toggle-ignore',
1146                 ];
1147
1148                 if ($contact['uid'] != 0) {
1149                         $contact_actions['delete'] = [
1150                                 'label' => DI::l10n()->t('Delete'),
1151                                 'url'   => 'contact/' . $contact['id'] . '/drop?t=' . $formSecurityToken,
1152                                 'title' => DI::l10n()->t('Delete contact'),
1153                                 'sel'   => '',
1154                                 'id'    => 'delete',
1155                         ];
1156                 }
1157
1158                 return $contact_actions;
1159         }
1160 }