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