]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact.php
Merge pull request #10696 from annando/photo-type
[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 = DBA::update('contact', [
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                                 DBA::update('contact', ['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                         $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'deleted' => false]);
294
295                         // Don't display contacts that are about to be deleted
296                         if ($contact['network'] == Protocol::PHANTOM) {
297                                 $contact = false;
298                         }
299                 }
300
301                 if (DBA::isResult($contact)) {
302                         if ($contact['self']) {
303                                 // @TODO: Replace with parameter from router
304                                 if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) {
305                                         DI::baseUrl()->redirect('profile/' . $contact['nick']);
306                                 } else {
307                                         DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile');
308                                 }
309                         }
310
311                         $vcard_widget = Widget\VCard::getHTML($contact);
312
313                         $findpeople_widget = '';
314                         $follow_widget = '';
315                         $account_widget = '';
316                         $networks_widget = '';
317                         $rel_widget = '';
318
319                         if ($contact['uid'] != 0) {
320                                 $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
321                         } else {
322                                 $groups_widget = '';
323                         }
324                 } else {
325                         $vcard_widget = '';
326                         $findpeople_widget = Widget::findPeople();
327                         if (isset($_GET['add'])) {
328                                 $follow_widget = Widget::follow($_GET['add']);
329                         } else {
330                                 $follow_widget = Widget::follow();
331                         }
332
333                         $account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
334                         $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
335                         $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
336                         $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group);
337                 }
338
339                 DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $account_widget . $groups_widget . $networks_widget . $rel_widget;
340
341                 $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
342                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
343                         '$baseurl' => DI::baseUrl()->get(true),
344                 ]);
345
346                 $o = '';
347                 Nav::setSelected('contact');
348
349                 if (!local_user()) {
350                         notice(DI::l10n()->t('Permission denied.'));
351                         return Login::form();
352                 }
353
354                 if (DI::args()->getArgc() == 3) {
355                         $contact_id = intval(DI::args()->getArgv()[1]);
356                         if (!$contact_id) {
357                                 throw new BadRequestException();
358                         }
359
360                         // @TODO: Replace with parameter from router
361                         $cmd = DI::args()->getArgv()[2];
362
363                         $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
364                         if (!DBA::isResult($orig_record)) {
365                                 throw new NotFoundException(DI::l10n()->t('Contact not found'));
366                         }
367
368                         if ($cmd === 'posts') {
369                                 return self::getPostsHTML($a, $contact_id);
370                         }
371
372                         if ($cmd === 'conversations') {
373                                 return self::getConversationsHMTL($a, $contact_id, $update);
374                         }
375
376                         self::checkFormSecurityTokenRedirectOnError('contact/' . $contact_id, 'contact_action', 't');
377
378                         $cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], local_user());
379                         if (empty($cdata)) {
380                                 throw new NotFoundException(DI::l10n()->t('Contact not found'));
381                         }
382
383                         if ($cmd === 'update' && $cdata['user']) {
384                                 self::updateContactFromPoll($cdata['user']);
385                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
386                                 // NOTREACHED
387                         }
388
389                         if ($cmd === 'updateprofile' && $cdata['user']) {
390                                 self::updateContactFromProbe($cdata['user']);
391                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
392                                 // NOTREACHED
393                         }
394
395                         if ($cmd === 'block') {
396                                 if (public_contact() === $cdata['public']) {
397                                         throw new BadRequestException(DI::l10n()->t('You can\'t block yourself'));
398                                 }
399
400                                 self::toggleBlockContact($cdata['public']);
401
402                                 $blocked = Model\Contact\User::isBlocked($contact_id, local_user());
403                                 info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')));
404
405                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
406                                 // NOTREACHED
407                         }
408
409                         if ($cmd === 'ignore') {
410                                 if (public_contact() === $cdata['public']) {
411                                         throw new BadRequestException(DI::l10n()->t('You can\'t ignore yourself'));
412                                 }
413
414                                 self::toggleIgnoreContact($cdata['public']);
415
416                                 $ignored = Model\Contact\User::isIgnored($cdata['public'], local_user());
417                                 info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')));
418
419                                 DI::baseUrl()->redirect('contact/' . $cdata['public']);
420                                 // NOTREACHED
421                         }
422
423                         if ($cmd === 'drop' && $cdata['user']) {
424                                 // Check if we should do HTML-based delete confirmation
425                                 if (!empty($_REQUEST['confirm'])) {
426                                         DI::page()['aside'] = '';
427
428                                         return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
429                                                 '$header' => DI::l10n()->t('Drop contact'),
430                                                 '$contact' => self::getContactTemplateVars($orig_record),
431                                                 '$method' => 'get',
432                                                 '$message' => DI::l10n()->t('Do you really want to delete this contact?'),
433                                                 '$confirm' => DI::l10n()->t('Yes'),
434                                                 '$confirm_url' => DI::args()->getCommand(),
435                                                 '$confirm_name' => 'confirmed',
436                                                 '$cancel' => DI::l10n()->t('Cancel'),
437                                         ]);
438                                 }
439                                 // Now check how the user responded to the confirmation query
440                                 if (!empty($_REQUEST['canceled'])) {
441                                         DI::baseUrl()->redirect('contact');
442                                 }
443
444                                 if (self::dropContact($cdata['user'], local_user())) {
445                                         info(DI::l10n()->t('Contact has been removed.'));
446                                 }
447
448                                 DI::baseUrl()->redirect('contact');
449                                 // NOTREACHED
450                         }
451                 }
452
453                 $_SESSION['return_path'] = DI::args()->getQueryString();
454
455                 if (!empty($contact)) {
456                         DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
457                                 '$baseurl' => DI::baseUrl()->get(true),
458                         ]);
459
460                         $contact['blocked']  = Model\Contact\User::isBlocked($contact['id'], local_user());
461                         $contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], local_user());
462
463                         $relation_text = '';
464                         switch ($contact['rel']) {
465                                 case Model\Contact::FRIEND:
466                                         $relation_text = DI::l10n()->t('You are mutual friends with %s');
467                                         break;
468
469                                 case Model\Contact::FOLLOWER;
470                                         $relation_text = DI::l10n()->t('You are sharing with %s');
471                                         break;
472
473                                 case Model\Contact::SHARING;
474                                         $relation_text = DI::l10n()->t('%s is sharing with you');
475                                         break;
476
477                                 default:
478                                         break;
479                         }
480
481                         if ($contact['uid'] == 0) {
482                                 $relation_text = '';
483                         }
484
485                         if (!in_array($contact['network'], array_merge(Protocol::FEDERATED, [Protocol::TWITTER]))) {
486                                 $relation_text = '';
487                         }
488
489                         $relation_text = sprintf($relation_text, $contact['name']);
490
491                         $url = Model\Contact::magicLinkByContact($contact);
492                         if (strpos($url, 'redir/') === 0) {
493                                 $sparkle = ' class="sparkle" ';
494                         } else {
495                                 $sparkle = '';
496                         }
497
498                         $insecure = DI::l10n()->t('Private communications are not available for this contact.');
499
500                         $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? DI::l10n()->t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
501
502                         if ($contact['last-update'] > DBA::NULL_DATETIME) {
503                                 $last_update .= ' ' . ($contact['failed'] ? DI::l10n()->t('(Update was not successful)') : DI::l10n()->t('(Update was successful)'));
504                         }
505                         $lblsuggest = (($contact['network'] === Protocol::DFRN) ? DI::l10n()->t('Suggest friends') : '');
506
507                         $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
508
509                         $nettype = DI::l10n()->t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']));
510
511                         // tabs
512                         $tab_str = self::getTabsHTML($contact, self::TAB_PROFILE);
513
514                         $lost_contact = (($contact['archive'] && $contact['term-date'] > DBA::NULL_DATETIME && $contact['term-date'] < DateTimeFormat::utcNow()) ? DI::l10n()->t('Communications lost with this contact!') : '');
515
516                         $fetch_further_information = null;
517                         if ($contact['network'] == Protocol::FEED) {
518                                 $fetch_further_information = [
519                                         'fetch_further_information',
520                                         DI::l10n()->t('Fetch further information for feeds'),
521                                         $contact['fetch_further_information'],
522                                         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.'),
523                                         [
524                                                 '0' => DI::l10n()->t('Disabled'),
525                                                 '1' => DI::l10n()->t('Fetch information'),
526                                                 '3' => DI::l10n()->t('Fetch keywords'),
527                                                 '2' => DI::l10n()->t('Fetch information and keywords')
528                                         ]
529                                 ];
530                         }
531
532                         // Disable remote self for everything except feeds.
533                         // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
534                         // Problem is, you couldn't reply to both networks.
535                         $allow_remote_self = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
536                                 && DI::config()->get('system', 'allow_users_remote_self');
537
538                         if ($contact['network'] == Protocol::FEED) {
539                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
540                                         Model\Contact::MIRROR_FORWARDED => DI::l10n()->t('Mirror as forwarded posting'),
541                                         Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
542                         } elseif (in_array($contact['network'], [Protocol::ACTIVITYPUB])) {
543                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
544                                 Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
545                         } elseif (in_array($contact['network'], [Protocol::DFRN])) {
546                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
547                                 Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting'),
548                                 Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
549                         } else {
550                                 $remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
551                                         Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
552                         }
553
554                         $poll_interval = null;
555                         if ((($contact['network'] == Protocol::FEED) && !DI::config()->get('system', 'adjust_poll_frequency')) || ($contact['network'] == Protocol::MAIL)) {
556                                 $poll_interval = ContactSelector::pollInterval($contact['priority'], !$poll_enabled);
557                         }
558
559                         // Load contactact related actions like hide, suggest, delete and others
560                         $contact_actions = self::getContactActions($contact);
561
562                         if ($contact['uid'] != 0) {
563                                 $lbl_info1 = DI::l10n()->t('Contact Information / Notes');
564                                 $contact_settings_label = DI::l10n()->t('Contact Settings');
565                         } else {
566                                 $lbl_info1 = null;
567                                 $contact_settings_label = null;
568                         }
569
570                         $tpl = Renderer::getMarkupTemplate('contact_edit.tpl');
571                         $o .= Renderer::replaceMacros($tpl, [
572                                 '$header'         => DI::l10n()->t('Contact'),
573                                 '$tab_str'        => $tab_str,
574                                 '$submit'         => DI::l10n()->t('Submit'),
575                                 '$lbl_info1'      => $lbl_info1,
576                                 '$lbl_info2'      => DI::l10n()->t('Their personal note'),
577                                 '$reason'         => trim(Strings::escapeTags($contact['reason'])),
578                                 '$infedit'        => DI::l10n()->t('Edit contact notes'),
579                                 '$common_link'    => 'contact/' . $contact['id'] . '/contacts/common',
580                                 '$relation_text'  => $relation_text,
581                                 '$visit'          => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
582                                 '$blockunblock'   => DI::l10n()->t('Block/Unblock contact'),
583                                 '$ignorecont'     => DI::l10n()->t('Ignore contact'),
584                                 '$lblrecent'      => DI::l10n()->t('View conversations'),
585                                 '$lblsuggest'     => $lblsuggest,
586                                 '$nettype'        => $nettype,
587                                 '$poll_interval'  => $poll_interval,
588                                 '$poll_enabled'   => $poll_enabled,
589                                 '$lastupdtext'    => DI::l10n()->t('Last update:'),
590                                 '$lost_contact'   => $lost_contact,
591                                 '$updpub'         => DI::l10n()->t('Update public posts'),
592                                 '$last_update'    => $last_update,
593                                 '$udnow'          => DI::l10n()->t('Update now'),
594                                 '$contact_id'     => $contact['id'],
595                                 '$block_text'     => ($contact['blocked'] ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')),
596                                 '$ignore_text'    => ($contact['readonly'] ? DI::l10n()->t('Unignore') : DI::l10n()->t('Ignore')),
597                                 '$insecure'       => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
598                                 '$info'           => $contact['info'],
599                                 '$cinfo'          => ['info', '', $contact['info'], ''],
600                                 '$blocked'        => ($contact['blocked'] ? DI::l10n()->t('Currently blocked') : ''),
601                                 '$ignored'        => ($contact['readonly'] ? DI::l10n()->t('Currently ignored') : ''),
602                                 '$archived'       => ($contact['archive'] ? DI::l10n()->t('Currently archived') : ''),
603                                 '$pending'        => ($contact['pending'] ? DI::l10n()->t('Awaiting connection acknowledge') : ''),
604                                 '$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')],
605                                 '$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')],
606                                 '$fetch_further_information' => $fetch_further_information,
607                                 '$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')],
608                                 '$photo'          => Model\Contact::getPhoto($contact),
609                                 '$name'           => $contact['name'],
610                                 '$sparkle'        => $sparkle,
611                                 '$url'            => $url,
612                                 '$profileurllabel'=> DI::l10n()->t('Profile URL'),
613                                 '$profileurl'     => $contact['url'],
614                                 '$account_type'   => Model\Contact::getAccountType($contact),
615                                 '$location'       => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
616                                 '$location_label' => DI::l10n()->t('Location:'),
617                                 '$xmpp'           => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
618                                 '$xmpp_label'     => DI::l10n()->t('XMPP:'),
619                                 '$matrix'         => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['matrix']),
620                                 '$matrix_label'   => DI::l10n()->t('Matrix:'),
621                                 '$about'          => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'], BBCode::EXTERNAL),
622                                 '$about_label'    => DI::l10n()->t('About:'),
623                                 '$keywords'       => $contact['keywords'],
624                                 '$keywords_label' => DI::l10n()->t('Tags:'),
625                                 '$contact_action_button' => DI::l10n()->t('Actions'),
626                                 '$contact_actions'=> $contact_actions,
627                                 '$contact_status' => DI::l10n()->t('Status'),
628                                 '$contact_settings_label' => $contact_settings_label,
629                                 '$contact_profile_label' => DI::l10n()->t('Profile'),
630                                 '$allow_remote_self' => $allow_remote_self,
631                                 '$remote_self'       => ['remote_self',
632                                         DI::l10n()->t('Mirror postings from this contact'),
633                                         $contact['remote_self'],
634                                         DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
635                                         $remote_self_options
636                                 ],
637                         ]);
638
639                         $arr = ['contact' => $contact, 'output' => $o];
640
641                         Hook::callAll('contact_edit', $arr);
642
643                         return $arr['output'];
644                 }
645
646                 $sql_values = [local_user()];
647
648                 // @TODO: Replace with parameter from router
649                 $type = DI::args()->getArgv()[1] ?? '';
650
651                 switch ($type) {
652                         case 'blocked':
653                                 $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`blocked`)";
654                                 // This makes the query look for contact.uid = 0
655                                 array_unshift($sql_values, 0);
656                                 break;
657                         case 'hidden':
658                                 $sql_extra = " AND `hidden` AND NOT `blocked` AND NOT `pending`";
659                                 break;
660                         case 'ignored':
661                                 $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`ignored`)";
662                                 // This makes the query look for contact.uid = 0
663                                 array_unshift($sql_values, 0);
664                                 break;
665                         case 'archived':
666                                 $sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
667                                 break;
668                         case 'pending':
669                                 $sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
670                                         OR EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id` AND NOT `ignore`))";
671                                 $sql_values[] = Model\Contact::SHARING;
672                                 break;
673                         default:
674                                 $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`";
675                                 break;
676                 }
677
678                 if (isset($accounttypeid)) {
679                         $sql_extra .= " AND `contact-type` = ?";
680                         $sql_values[] = $accounttypeid;
681                 }
682
683                 $searching = false;
684                 $search_hdr = null;
685                 if ($search) {
686                         $searching = true;
687                         $search_hdr = $search;
688                         $search_txt = preg_quote($search);
689                         $sql_extra .= " AND (name REGEXP ? OR url REGEXP ? OR nick REGEXP ?)";
690                         $sql_values[] = $search_txt;
691                         $sql_values[] = $search_txt;
692                         $sql_values[] = $search_txt;
693                 }
694
695                 if ($nets) {
696                         $sql_extra .= " AND network = ? ";
697                         $sql_values[] = $nets;
698                 }
699
700                 switch ($rel) {
701                         case 'followers':
702                                 $sql_extra .= " AND `rel` IN (?, ?)";
703                                 $sql_values[] = Model\Contact::FOLLOWER;
704                                 $sql_values[] = Model\Contact::FRIEND;
705                                 break;
706                         case 'following':
707                                 $sql_extra .= " AND `rel` IN (?, ?)";
708                                 $sql_values[] = Model\Contact::SHARING;
709                                 $sql_values[] = Model\Contact::FRIEND;
710                                 break;
711                         case 'mutuals':
712                                 $sql_extra .= " AND `rel` = ?";
713                                 $sql_values[] = Model\Contact::FRIEND;
714                                 break;
715                 }
716
717                 if ($group) {
718                         $sql_extra = " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)";
719                         $sql_values[] = $group;
720                 }
721
722                 $total = 0;
723                 $stmt = DBA::p("SELECT COUNT(*) AS `total`
724                         FROM `contact`
725                         WHERE `uid` = ?
726                         AND `self` = 0
727                         AND NOT `deleted`
728                         $sql_extra
729                         " . Widget::unavailableNetworks(),
730                         $sql_values
731                 );
732                 if (DBA::isResult($stmt)) {
733                         $total = DBA::fetch($stmt)['total'];
734                 }
735                 DBA::close($stmt);
736
737                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
738
739                 $sql_values[] = $pager->getStart();
740                 $sql_values[] = $pager->getItemsPerPage();
741
742                 $contacts = [];
743
744                 $stmt = DBA::p("SELECT *
745                         FROM `contact`
746                         WHERE `uid` = ?
747                         AND `self` = 0
748                         AND NOT `deleted`
749                         $sql_extra
750                         ORDER BY `name` ASC
751                         LIMIT ?, ?",
752                         $sql_values
753                 );
754                 while ($contact = DBA::fetch($stmt)) {
755                         $contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], local_user());
756                         $contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], local_user());
757                         $contacts[] = self::getContactTemplateVars($contact);
758                 }
759                 DBA::close($stmt);
760
761                 $tabs = [
762                         [
763                                 'label' => DI::l10n()->t('All Contacts'),
764                                 'url'   => 'contact',
765                                 'sel'   => !$type ? 'active' : '',
766                                 'title' => DI::l10n()->t('Show all contacts'),
767                                 'id'    => 'showall-tab',
768                                 'accesskey' => 'l',
769                         ],
770                         [
771                                 'label' => DI::l10n()->t('Pending'),
772                                 'url'   => 'contact/pending',
773                                 'sel'   => $type == 'pending' ? 'active' : '',
774                                 'title' => DI::l10n()->t('Only show pending contacts'),
775                                 'id'    => 'showpending-tab',
776                                 'accesskey' => 'p',
777                         ],
778                         [
779                                 'label' => DI::l10n()->t('Blocked'),
780                                 'url'   => 'contact/blocked',
781                                 'sel'   => $type == 'blocked' ? 'active' : '',
782                                 'title' => DI::l10n()->t('Only show blocked contacts'),
783                                 'id'    => 'showblocked-tab',
784                                 'accesskey' => 'b',
785                         ],
786                         [
787                                 'label' => DI::l10n()->t('Ignored'),
788                                 'url'   => 'contact/ignored',
789                                 'sel'   => $type == 'ignored' ? 'active' : '',
790                                 'title' => DI::l10n()->t('Only show ignored contacts'),
791                                 'id'    => 'showignored-tab',
792                                 'accesskey' => 'i',
793                         ],
794                         [
795                                 'label' => DI::l10n()->t('Archived'),
796                                 'url'   => 'contact/archived',
797                                 'sel'   => $type == 'archived' ? 'active' : '',
798                                 'title' => DI::l10n()->t('Only show archived contacts'),
799                                 'id'    => 'showarchived-tab',
800                                 'accesskey' => 'y',
801                         ],
802                         [
803                                 'label' => DI::l10n()->t('Hidden'),
804                                 'url'   => 'contact/hidden',
805                                 'sel'   => $type == 'hidden' ? 'active' : '',
806                                 'title' => DI::l10n()->t('Only show hidden contacts'),
807                                 'id'    => 'showhidden-tab',
808                                 'accesskey' => 'h',
809                         ],
810                         [
811                                 'label' => DI::l10n()->t('Groups'),
812                                 'url'   => 'group',
813                                 'sel'   => '',
814                                 'title' => DI::l10n()->t('Organize your contact groups'),
815                                 'id'    => 'contactgroups-tab',
816                                 'accesskey' => 'e',
817                         ],
818                 ];
819
820                 $tabs_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
821                 $tabs_html = Renderer::replaceMacros($tabs_tpl, ['$tabs' => $tabs]);
822
823                 switch ($rel) {
824                         case 'followers': $header = DI::l10n()->t('Followers'); break;
825                         case 'following': $header = DI::l10n()->t('Following'); break;
826                         case 'mutuals':   $header = DI::l10n()->t('Mutual friends'); break;
827                         default:          $header = DI::l10n()->t('Contacts');
828                 }
829
830                 switch ($type) {
831                         case 'pending':  $header .= ' - ' . DI::l10n()->t('Pending'); break;
832                         case 'blocked':  $header .= ' - ' . DI::l10n()->t('Blocked'); break;
833                         case 'hidden':   $header .= ' - ' . DI::l10n()->t('Hidden'); break;
834                         case 'ignored':  $header .= ' - ' . DI::l10n()->t('Ignored'); break;
835                         case 'archived': $header .= ' - ' . DI::l10n()->t('Archived'); break;
836                 }
837
838                 $header .= $nets ? ' - ' . ContactSelector::networkToName($nets) : '';
839
840                 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
841                 $o .= Renderer::replaceMacros($tpl, [
842                         '$header'     => $header,
843                         '$tabs'       => $tabs_html,
844                         '$total'      => $total,
845                         '$search'     => $search_hdr,
846                         '$desc'       => DI::l10n()->t('Search your contacts'),
847                         '$finding'    => $searching ? DI::l10n()->t('Results for: %s', $search) : '',
848                         '$submit'     => DI::l10n()->t('Find'),
849                         '$cmd'        => DI::args()->getCommand(),
850                         '$contacts'   => $contacts,
851                         '$form_security_token'  => BaseModule::getFormSecurityToken('contact_batch_actions'),
852                         '$contact_drop_confirm' => DI::l10n()->t('Do you really want to delete this contact?'),
853                         'multiselect' => 1,
854                         '$batch_actions' => [
855                                 'contacts_batch_update'  => DI::l10n()->t('Update'),
856                                 'contacts_batch_block'   => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
857                                 'contacts_batch_ignore'  => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
858                                 'contacts_batch_drop'    => DI::l10n()->t('Delete'),
859                         ],
860                         '$h_batch_actions' => DI::l10n()->t('Batch Actions'),
861                         '$paginate'   => $pager->renderFull($total),
862                 ]);
863
864                 return $o;
865         }
866
867         /**
868          * List of pages for the Contact TabBar
869          *
870          * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
871          *
872          * @param array $contact    The contact array
873          * @param int   $active_tab 1 if tab should be marked as active
874          *
875          * @return string HTML string of the contact page tabs buttons.
876          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
877          * @throws \ImagickException
878          */
879         public static function getTabsHTML(array $contact, int $active_tab)
880         {
881                 $cid = $pcid = $contact['id'];
882                 $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user());
883                 if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
884                         $cid = $data['user'];
885                 } elseif (!empty($data['public'])) {
886                         $pcid = $data['public'];
887                 }
888
889                 // tabs
890                 $tabs = [
891                         [
892                                 'label' => DI::l10n()->t('Status'),
893                                 'url'   => 'contact/' . $pcid . '/conversations',
894                                 'sel'   => (($active_tab == self::TAB_CONVERSATIONS) ? 'active' : ''),
895                                 'title' => DI::l10n()->t('Conversations started by this contact'),
896                                 'id'    => 'status-tab',
897                                 'accesskey' => 'm',
898                         ],
899                         [
900                                 'label' => DI::l10n()->t('Posts and Comments'),
901                                 'url'   => 'contact/' . $pcid . '/posts',
902                                 'sel'   => (($active_tab == self::TAB_POSTS) ? 'active' : ''),
903                                 'title' => DI::l10n()->t('Status Messages and Posts'),
904                                 'id'    => 'posts-tab',
905                                 'accesskey' => 'p',
906                         ],
907                         [
908                                 'label' => DI::l10n()->t('Profile'),
909                                 'url'   => 'contact/' . $cid,
910                                 'sel'   => (($active_tab == self::TAB_PROFILE) ? 'active' : ''),
911                                 'title' => DI::l10n()->t('Profile Details'),
912                                 'id'    => 'profile-tab',
913                                 'accesskey' => 'o',
914                         ],
915                         ['label' => DI::l10n()->t('Contacts'),
916                                 'url'   => 'contact/' . $pcid . '/contacts',
917                                 'sel'   => (($active_tab == self::TAB_CONTACTS) ? 'active' : ''),
918                                 'title' => DI::l10n()->t('View all known contacts'),
919                                 'id'    => 'contacts-tab',
920                                 'accesskey' => 't'
921                         ],
922                 ];
923
924                 if (!empty($contact['network']) && in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && ($cid != $pcid)) {
925                         $tabs[] = ['label' => DI::l10n()->t('Advanced'),
926                                 'url'   => 'contact/' . $cid . '/advanced/',
927                                 'sel'   => (($active_tab == self::TAB_ADVANCED) ? 'active' : ''),
928                                 'title' => DI::l10n()->t('Advanced Contact Settings'),
929                                 'id'    => 'advanced-tab',
930                                 'accesskey' => 'r'
931                         ];
932                 }
933
934                 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
935                 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
936
937                 return $tab_str;
938         }
939
940         public static function getConversationsHMTL($a, $contact_id, $update, $parent = 0)
941         {
942                 $o = '';
943
944                 if (!$update) {
945                         // We need the editor here to be able to reshare an item.
946                         if (local_user()) {
947                                 $o = status_editor($a, [], 0, true);
948                         }
949                 }
950
951                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
952
953                 if (!$update) {
954                         $o .= self::getTabsHTML($contact, self::TAB_CONVERSATIONS);
955                 }
956
957                 if (DBA::isResult($contact)) {
958                         if (!$update) {
959                                 $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
960                                 DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
961                         } else {
962                                 DI::page()['aside'] = '';
963                         }
964
965                         if ($contact['uid'] == 0) {
966                                 $o .= Model\Contact::getPostsFromId($contact['id'], true, $update, $parent);
967                         } else {
968                                 $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update, $parent);
969                         }
970                 }
971
972                 return $o;
973         }
974
975         private static function getPostsHTML($a, $contact_id)
976         {
977                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
978
979                 $o = self::getTabsHTML($contact, self::TAB_POSTS);
980
981                 if (DBA::isResult($contact)) {
982                         $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
983
984                         if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
985                                 $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
986                         }
987
988                         DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
989
990                         if ($contact['uid'] == 0) {
991                                 $o .= Model\Contact::getPostsFromId($contact['id']);
992                         } else {
993                                 $o .= Model\Contact::getPostsFromUrl($contact['url']);
994                         }
995                 }
996
997                 return $o;
998         }
999
1000         /**
1001          * Return the fields for the contact template
1002          *
1003          * @param array $contact Contact array
1004          * @return array Template fields
1005          */
1006         public static function getContactTemplateVars(array $contact)
1007         {
1008                 $alt_text = '';
1009
1010                 if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && local_user()) {
1011                         $personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], local_user());
1012                         if (!empty($personal)) {
1013                                 $contact['uid'] = $personal['uid'];
1014                                 $contact['rel'] = $personal['rel'];
1015                                 $contact['self'] = $personal['self'];
1016                         }
1017                 }
1018
1019                 if (!empty($contact['uid']) && !empty($contact['rel']) && local_user() == $contact['uid']) {
1020                         switch ($contact['rel']) {
1021                                 case Model\Contact::FRIEND:
1022                                         $alt_text = DI::l10n()->t('Mutual Friendship');
1023                                         break;
1024
1025                                 case Model\Contact::FOLLOWER;
1026                                         $alt_text = DI::l10n()->t('is a fan of yours');
1027                                         break;
1028
1029                                 case Model\Contact::SHARING;
1030                                         $alt_text = DI::l10n()->t('you are a fan of');
1031                                         break;
1032
1033                                 default:
1034                                         break;
1035                         }
1036                 }
1037
1038                 $url = Model\Contact::magicLinkByContact($contact);
1039
1040                 if (strpos($url, 'redir/') === 0) {
1041                         $sparkle = ' class="sparkle" ';
1042                 } else {
1043                         $sparkle = '';
1044                 }
1045
1046                 if ($contact['pending']) {
1047                         if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
1048                                 $alt_text = DI::l10n()->t('Pending outgoing contact request');
1049                         } else {
1050                                 $alt_text = DI::l10n()->t('Pending incoming contact request');
1051                         }
1052                 }
1053
1054                 if ($contact['self']) {
1055                         $alt_text = DI::l10n()->t('This is you');
1056                         $url = $contact['url'];
1057                         $sparkle = '';
1058                 }
1059
1060                 return [
1061                         'id'           => $contact['id'],
1062                         'url'          => $url,
1063                         'img_hover'    => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
1064                         'photo_menu'   => Model\Contact::photoMenu($contact),
1065                         'thumb'        => Model\Contact::getThumb($contact, true),
1066                         'alt_text'     => $alt_text,
1067                         'name'         => $contact['name'],
1068                         'nick'         => $contact['nick'],
1069                         'details'      => $contact['location'],
1070                         'tags'         => $contact['keywords'],
1071                         'about'        => $contact['about'],
1072                         'account_type' => Model\Contact::getAccountType($contact),
1073                         'sparkle'      => $sparkle,
1074                         'itemurl'      => ($contact['addr'] ?? '') ?: $contact['url'],
1075                         'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
1076                 ];
1077         }
1078
1079         /**
1080          * Gives a array with actions which can performed to a given contact
1081          *
1082          * This includes actions like e.g. 'block', 'hide', 'delete' and others
1083          *
1084          * @param array $contact Data about the Contact
1085          * @return array with contact related actions
1086          */
1087         private static function getContactActions($contact)
1088         {
1089                 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1090                 $contact_actions = [];
1091
1092                 $formSecurityToken = self::getFormSecurityToken('contact_action');
1093
1094                 // Provide friend suggestion only for Friendica contacts
1095                 if ($contact['network'] === Protocol::DFRN) {
1096                         $contact_actions['suggest'] = [
1097                                 'label' => DI::l10n()->t('Suggest friends'),
1098                                 'url'   => 'fsuggest/' . $contact['id'],
1099                                 'title' => '',
1100                                 'sel'   => '',
1101                                 'id'    => 'suggest',
1102                         ];
1103                 }
1104
1105                 if ($poll_enabled) {
1106                         $contact_actions['update'] = [
1107                                 'label' => DI::l10n()->t('Update now'),
1108                                 'url'   => 'contact/' . $contact['id'] . '/update?t=' . $formSecurityToken,
1109                                 'title' => '',
1110                                 'sel'   => '',
1111                                 'id'    => 'update',
1112                         ];
1113                 }
1114
1115                 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
1116                         $contact_actions['updateprofile'] = [
1117                                 'label' => DI::l10n()->t('Refetch contact data'),
1118                                 'url'   => 'contact/' . $contact['id'] . '/updateprofile?t=' . $formSecurityToken,
1119                                 'title' => '',
1120                                 'sel'   => '',
1121                                 'id'    => 'updateprofile',
1122                         ];
1123                 }
1124
1125                 $contact_actions['block'] = [
1126                         'label' => (intval($contact['blocked']) ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')),
1127                         'url'   => 'contact/' . $contact['id'] . '/block?t=' . $formSecurityToken,
1128                         'title' => DI::l10n()->t('Toggle Blocked status'),
1129                         'sel'   => (intval($contact['blocked']) ? 'active' : ''),
1130                         'id'    => 'toggle-block',
1131                 ];
1132
1133                 $contact_actions['ignore'] = [
1134                         'label' => (intval($contact['readonly']) ? DI::l10n()->t('Unignore') : DI::l10n()->t('Ignore')),
1135                         'url'   => 'contact/' . $contact['id'] . '/ignore?t=' . $formSecurityToken,
1136                         'title' => DI::l10n()->t('Toggle Ignored status'),
1137                         'sel'   => (intval($contact['readonly']) ? 'active' : ''),
1138                         'id'    => 'toggle-ignore',
1139                 ];
1140
1141                 if ($contact['uid'] != 0) {
1142                         $contact_actions['delete'] = [
1143                                 'label' => DI::l10n()->t('Delete'),
1144                                 'url'   => 'contact/' . $contact['id'] . '/drop?t=' . $formSecurityToken,
1145                                 'title' => DI::l10n()->t('Delete contact'),
1146                                 'sel'   => '',
1147                                 'id'    => 'delete',
1148                         ];
1149                 }
1150
1151                 return $contact_actions;
1152         }
1153 }