]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact.php
Decouple conversation creation from rendering
[friendica.git] / src / Module / Contact.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Widget;
29 use Friendica\Core\Logger;
30 use Friendica\Core\Protocol;
31 use Friendica\Core\Renderer;
32 use Friendica\Core\System;
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\InternalServerErrorException;
41 use Friendica\Network\HTTPException\NotFoundException;
42 use Friendica\Worker\UpdateContact;
43
44 /**
45  *  Manages and show Contacts and their content
46  */
47 class Contact extends BaseModule
48 {
49         const TAB_CONVERSATIONS = 1;
50         const TAB_POSTS = 2;
51         const TAB_PROFILE = 3;
52         const TAB_CONTACTS = 4;
53         const TAB_ADVANCED = 5;
54         const TAB_MEDIA = 6;
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, DI::userSession()->getLocalUserId()], 'self' => false, 'deleted' => false]);
67
68                 $count_actions = 0;
69                 foreach ($orig_records as $orig_record) {
70                         $cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], DI::userSession()->getLocalUserId());
71                         if (empty($cdata) || DI::userSession()->getPublicContactId() === $cdata['public']) {
72                                 // No action available on your own contact
73                                 continue;
74                         }
75
76                         if (!empty($_POST['contacts_batch_update']) && $cdata['user']) {
77                                 self::updateContactFromPoll($cdata['user']);
78                                 $count_actions++;
79                         }
80
81                         if (!empty($_POST['contacts_batch_block'])) {
82                                 self::toggleBlockContact($cdata['public'], DI::userSession()->getLocalUserId());
83                                 $count_actions++;
84                         }
85
86                         if (!empty($_POST['contacts_batch_ignore'])) {
87                                 self::toggleIgnoreContact($cdata['public']);
88                                 $count_actions++;
89                         }
90
91                         if (!empty($_POST['contacts_batch_collapse'])) {
92                                 self::toggleCollapseContact($cdata['public']);
93                                 $count_actions++;
94                         }
95                 }
96                 if ($count_actions > 0) {
97                         DI::sysmsg()->addInfo(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions));
98                 }
99
100                 DI::baseUrl()->redirect($redirectUrl);
101         }
102
103         protected function post(array $request = [])
104         {
105                 if (!DI::userSession()->getLocalUserId()) {
106                         return;
107                 }
108
109                 // @TODO: Replace with parameter from router
110                 if (DI::args()->getArgv()[1] === 'batch') {
111                         self::batchActions();
112                 }
113         }
114
115         /* contact actions */
116
117         /**
118          * @param int $contact_id Id of contact with uid != 0
119          * @throws NotFoundException
120          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
121          * @throws \ImagickException
122          */
123         public static function updateContactFromPoll(int $contact_id)
124         {
125                 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => DI::userSession()->getLocalUserId(), 'deleted' => false]);
126                 if (!DBA::isResult($contact)) {
127                         return;
128                 }
129
130                 if ($contact['network'] == Protocol::OSTATUS) {
131                         $result = Model\Contact::createFromProbeForUser($contact['uid'], $contact['url'], $contact['network']);
132
133                         if ($result['success']) {
134                                 Model\Contact::update(['subhub' => 1], ['id' => $contact_id]);
135                         }
136
137                         // pull feed and consume it, which should subscribe to the hub.
138                         Worker::add(Worker::PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
139                 } else {
140                         try {
141                                 UpdateContact::add(Worker::PRIORITY_HIGH, $contact_id);
142                         } catch (\InvalidArgumentException $e) {
143                                 Logger::notice($e->getMessage(), ['contact' => $contact, 'callstack' => System::callstack()]);
144                         }
145                 }
146         }
147
148         /**
149          * Toggles the blocked status of a contact identified by id.
150          *
151          * @param int $contact_id Id of the contact with uid = 0
152          * @param int $owner_id   Id of the user we want to block the contact for
153          * @throws \Exception
154          */
155         private static function toggleBlockContact(int $contact_id, int $owner_id)
156         {
157                 $blocked = !Model\Contact\User::isBlocked($contact_id, $owner_id);
158                 Model\Contact\User::setBlocked($contact_id, $owner_id, $blocked);
159         }
160
161         /**
162          * Toggles the ignored status of a contact identified by id.
163          *
164          * @param int $contact_id Id of the contact with uid = 0
165          * @throws \Exception
166          */
167         private static function toggleIgnoreContact(int $contact_id)
168         {
169                 $ignored = !Model\Contact\User::isIgnored($contact_id, DI::userSession()->getLocalUserId());
170                 Model\Contact\User::setIgnored($contact_id, DI::userSession()->getLocalUserId(), $ignored);
171         }
172
173         /**
174          * Toggles the collapsed status of a contact identified by id.
175          *
176          * @param int $contact_id Id of the contact with uid = 0
177          * @throws \Exception
178          */
179         private static function toggleCollapseContact(int $contact_id)
180         {
181                 $collapsed = !Model\Contact\User::isCollapsed($contact_id, DI::userSession()->getLocalUserId());
182                 Model\Contact\User::setCollapsed($contact_id, DI::userSession()->getLocalUserId(), $collapsed);
183         }
184
185         protected function content(array $request = []): string
186         {
187                 if (!DI::userSession()->getLocalUserId()) {
188                         return Login::form($_SERVER['REQUEST_URI']);
189                 }
190
191                 $search = trim($_GET['search'] ?? '');
192                 $nets   = trim($_GET['nets']   ?? '');
193                 $rel    = trim($_GET['rel']    ?? '');
194                 $circle = trim($_GET['circle'] ?? '');
195
196                 $accounttype = $_GET['accounttype'] ?? '';
197                 $accounttypeid = User::getAccountTypeByString($accounttype);
198
199                 $page = DI::page();
200
201                 $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
202                 $page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
203                 $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
204                 $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
205
206                 $vcard_widget = '';
207                 $findpeople_widget = Widget::findPeople();
208                 if (isset($_GET['add'])) {
209                         $follow_widget = Widget::follow($_GET['add']);
210                 } else {
211                         $follow_widget = Widget::follow();
212                 }
213
214                 $account_widget  = Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
215                 $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
216                 $rel_widget      = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
217                 $circles_widget  = Widget::circles($_SERVER['REQUEST_URI'], $circle);
218
219                 DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $rel_widget . $circles_widget . $networks_widget . $account_widget;
220
221                 $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
222                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, []);
223
224                 $o = '';
225                 Nav::setSelected('contact');
226
227                 $_SESSION['return_path'] = DI::args()->getQueryString();
228
229                 $sql_values = [DI::userSession()->getLocalUserId()];
230
231                 // @TODO: Replace with parameter from router
232                 $type = DI::args()->getArgv()[1] ?? '';
233
234                 switch ($type) {
235                         case 'blocked':
236                                 $sql_extra = " AND `id` IN (SELECT `cid` FROM `user-contact` WHERE `user-contact`.`uid` = ? AND `user-contact`.`blocked`)";
237                                 // This makes the query look for contact.uid = 0
238                                 array_unshift($sql_values, 0);
239                                 break;
240                         case 'hidden':
241                                 $sql_extra = " AND `hidden` AND NOT `blocked` AND NOT `pending`";
242                                 break;
243                         case 'ignored':
244                                 $sql_extra = " AND `id` IN (SELECT `cid` FROM `user-contact` WHERE `user-contact`.`uid` = ? AND `user-contact`.`ignored`)";
245                                 // This makes the query look for contact.uid = 0
246                                 array_unshift($sql_values, 0);
247                                 break;
248                         case 'collapsed':
249                                 $sql_extra = " AND `id` IN (SELECT `cid` FROM `user-contact` WHERE `user-contact`.`uid` = ? AND `user-contact`.`collapsed`)";
250                                 // This makes the query look for contact.uid = 0
251                                 array_unshift($sql_values, 0);
252                                 break;
253                         case 'archived':
254                                 $sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
255                                 break;
256                         case 'pending':
257                                 $sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
258                                         OR `id` IN (SELECT `contact-id` FROM `intro` WHERE `intro`.`uid` = ? AND NOT `ignore`))";
259                                 $sql_values[] = Model\Contact::SHARING;
260                                 $sql_values[] = DI::userSession()->getLocalUserId();
261                                 break;
262                         default:
263                                 $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`";
264                                 break;
265                 }
266
267                 if (isset($accounttypeid)) {
268                         $sql_extra .= " AND `contact-type` = ?";
269                         $sql_values[] = $accounttypeid;
270                 }
271
272                 $searching = false;
273                 $search_hdr = null;
274                 if ($search) {
275                         $searching = true;
276                         $search_hdr = $search;
277                         $search_txt = preg_quote(trim($search, ' @!'));
278                         $sql_extra .= " AND (`name` REGEXP ? OR `url` REGEXP ? OR `nick` REGEXP ? OR `addr` REGEXP ? OR `alias` REGEXP ?)";
279                         $sql_values[] = $search_txt;
280                         $sql_values[] = $search_txt;
281                         $sql_values[] = $search_txt;
282                         $sql_values[] = $search_txt;
283                         $sql_values[] = $search_txt;
284                 }
285
286                 if ($nets) {
287                         $sql_extra .= " AND network = ? ";
288                         $sql_values[] = $nets;
289                 }
290
291                 switch ($rel) {
292                         case 'followers':
293                                 $sql_extra .= " AND `rel` IN (?, ?)";
294                                 $sql_values[] = Model\Contact::FOLLOWER;
295                                 $sql_values[] = Model\Contact::FRIEND;
296                                 break;
297                         case 'following':
298                                 $sql_extra .= " AND `rel` IN (?, ?)";
299                                 $sql_values[] = Model\Contact::SHARING;
300                                 $sql_values[] = Model\Contact::FRIEND;
301                                 break;
302                         case 'mutuals':
303                                 $sql_extra .= " AND `rel` = ?";
304                                 $sql_values[] = Model\Contact::FRIEND;
305                                 break;
306                         case 'nothing':
307                                 $sql_extra .= " AND `rel` = ?";
308                                 $sql_values[] = Model\Contact::NOTHING;
309                                 break;
310                         default:
311                                 $sql_extra .= " AND `rel` != ?";
312                                 $sql_values[] = Model\Contact::NOTHING;
313                                 break;
314                 }
315
316                 if ($circle) {
317                         $sql_extra .= " AND `id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)";
318                         $sql_values[] = $circle;
319                 }
320
321                 $networks = Widget::unavailableNetworks();
322                 $sql_extra .= " AND NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")";
323                 $sql_values = array_merge($sql_values, $networks);
324
325                 $condition = ["`uid` = ? AND NOT `self` AND NOT `deleted`" . $sql_extra];
326                 $condition = array_merge($condition, $sql_values);
327
328                 $total = DBA::count('contact', $condition);
329
330                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
331
332                 $contacts = [];
333
334                 $stmt = DBA::select('contact', [], $condition, ['order' => ['name'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
335
336                 while ($contact = DBA::fetch($stmt)) {
337                         $contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], DI::userSession()->getLocalUserId());
338                         $contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], DI::userSession()->getLocalUserId());
339                         $contacts[] = self::getContactTemplateVars($contact);
340                 }
341                 DBA::close($stmt);
342
343                 $tabs = [
344                         [
345                                 'label' => DI::l10n()->t('All Contacts'),
346                                 'url'   => 'contact',
347                                 'sel'   => !$type ? 'active' : '',
348                                 'title' => DI::l10n()->t('Show all contacts'),
349                                 'id'    => 'showall-tab',
350                                 'accesskey' => 'l',
351                         ],
352                         [
353                                 'label' => DI::l10n()->t('Pending'),
354                                 'url'   => 'contact/pending',
355                                 'sel'   => $type == 'pending' ? 'active' : '',
356                                 'title' => DI::l10n()->t('Only show pending contacts'),
357                                 'id'    => 'showpending-tab',
358                                 'accesskey' => 'p',
359                         ],
360                         [
361                                 'label' => DI::l10n()->t('Blocked'),
362                                 'url'   => 'contact/blocked',
363                                 'sel'   => $type == 'blocked' ? 'active' : '',
364                                 'title' => DI::l10n()->t('Only show blocked contacts'),
365                                 'id'    => 'showblocked-tab',
366                                 'accesskey' => 'b',
367                         ],
368                         [
369                                 'label' => DI::l10n()->t('Ignored'),
370                                 'url'   => 'contact/ignored',
371                                 'sel'   => $type == 'ignored' ? 'active' : '',
372                                 'title' => DI::l10n()->t('Only show ignored contacts'),
373                                 'id'    => 'showignored-tab',
374                                 'accesskey' => 'i',
375                         ],
376                         [
377                                 'label' => DI::l10n()->t('Collapsed'),
378                                 'url'   => 'contact/collapsed',
379                                 'sel'   => $type == 'collapsed' ? 'active' : '',
380                                 'title' => DI::l10n()->t('Only show collapsed contacts'),
381                                 'id'    => 'showcollapsed-tab',
382                                 'accesskey' => 'c',
383                         ],
384                         [
385                                 'label' => DI::l10n()->t('Archived'),
386                                 'url'   => 'contact/archived',
387                                 'sel'   => $type == 'archived' ? 'active' : '',
388                                 'title' => DI::l10n()->t('Only show archived contacts'),
389                                 'id'    => 'showarchived-tab',
390                                 'accesskey' => 'y',
391                         ],
392                         [
393                                 'label' => DI::l10n()->t('Hidden'),
394                                 'url'   => 'contact/hidden',
395                                 'sel'   => $type == 'hidden' ? 'active' : '',
396                                 'title' => DI::l10n()->t('Only show hidden contacts'),
397                                 'id'    => 'showhidden-tab',
398                                 'accesskey' => 'h',
399                         ],
400                         [
401                                 'label' => DI::l10n()->t('Circles'),
402                                 'url'   => 'circle',
403                                 'sel'   => '',
404                                 'title' => DI::l10n()->t('Organize your contact circles'),
405                                 'id'    => 'contactcircles-tab',
406                                 'accesskey' => 'e',
407                         ],
408                 ];
409
410                 $tabs_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
411                 $tabs_html = Renderer::replaceMacros($tabs_tpl, ['$tabs' => $tabs]);
412
413                 switch ($rel) {
414                         case 'followers':
415                                 $header = DI::l10n()->t('Followers');
416                                 break;
417                         case 'following':
418                                 $header = DI::l10n()->t('Following');
419                                 break;
420                         case 'mutuals':
421                                 $header = DI::l10n()->t('Mutual friends');
422                                 break;
423                         case 'nothing':
424                                 $header = DI::l10n()->t('No relationship');
425                                 break;
426                         default:
427                                 $header = DI::l10n()->t('Contacts');
428                 }
429
430                 switch ($type) {
431                         case 'pending':
432                                 $header .= ' - ' . DI::l10n()->t('Pending');
433                                 break;
434                         case 'blocked':
435                                 $header .= ' - ' . DI::l10n()->t('Blocked');
436                                 break;
437                         case 'hidden':
438                                 $header .= ' - ' . DI::l10n()->t('Hidden');
439                                 break;
440                         case 'ignored':
441                                 $header .= ' - ' . DI::l10n()->t('Ignored');
442                                 break;
443                         case 'collapsed':
444                                 $header .= ' - ' . DI::l10n()->t('Collapsed');
445                                 break;
446                         case 'archived':
447                                 $header .= ' - ' . DI::l10n()->t('Archived');
448                                 break;
449                 }
450
451                 $header .= $nets ? ' - ' . ContactSelector::networkToName($nets) : '';
452
453                 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
454                 $o .= Renderer::replaceMacros($tpl, [
455                         '$header'     => $header,
456                         '$tabs'       => $tabs_html,
457                         '$total'      => $total,
458                         '$search'     => $search_hdr,
459                         '$desc'       => DI::l10n()->t('Search your contacts'),
460                         '$finding'    => $searching ? DI::l10n()->t('Results for: %s', $search) : '',
461                         '$submit'     => DI::l10n()->t('Find'),
462                         '$cmd'        => DI::args()->getCommand(),
463                         '$contacts'   => $contacts,
464                         '$form_security_token'  => BaseModule::getFormSecurityToken('contact_batch_actions'),
465                         'multiselect' => 1,
466                         '$batch_actions' => [
467                                 'contacts_batch_update'    => DI::l10n()->t('Update'),
468                                 'contacts_batch_block'     => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
469                                 'contacts_batch_ignore'    => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
470                                 'contacts_batch_collapse'  => DI::l10n()->t('Collapse') . '/' . DI::l10n()->t('Uncollapse'),
471                         ],
472                         '$h_batch_actions' => DI::l10n()->t('Batch Actions'),
473                         '$paginate'   => $pager->renderFull($total),
474                 ]);
475
476                 return $o;
477         }
478
479         /**
480          * List of pages for the Contact TabBar
481          *
482          * Available Pages are 'Conversations', 'Profile', 'Contacts' and 'Common Friends'
483          *
484          * @param array $contact    The contact array
485          * @param int   $active_tab 1 if tab should be marked as active
486          *
487          * @return string HTML string of the contact page tabs buttons.
488          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
489          * @throws \ImagickException
490          */
491         public static function getTabsHTML(array $contact, int $active_tab)
492         {
493                 $cid = $pcid = $contact['id'];
494                 $data = Model\Contact::getPublicAndUserContactID($contact['id'], DI::userSession()->getLocalUserId());
495                 if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
496                         $cid = $data['user'];
497                 } elseif (!empty($data['public'])) {
498                         $pcid = $data['public'];
499                 }
500
501                 // tabs
502                 $tabs = [
503                         [
504                                 'label' => DI::l10n()->t('Profile'),
505                                 'url'   => 'contact/' . $cid,
506                                 'sel'   => (($active_tab == self::TAB_PROFILE) ? 'active' : ''),
507                                 'title' => DI::l10n()->t('Profile Details'),
508                                 'id'    => 'profile-tab',
509                                 'accesskey' => 'o',
510                         ],
511                         [
512                                 'label' => DI::l10n()->t('Conversations'),
513                                 'url'   => 'contact/' . $pcid . '/conversations',
514                                 'sel'   => (($active_tab == self::TAB_CONVERSATIONS) ? 'active' : ''),
515                                 'title' => DI::l10n()->t('Conversations started by this contact'),
516                                 'id'    => 'status-tab',
517                                 'accesskey' => 'm',
518                         ],
519                         [
520                                 'label' => DI::l10n()->t('Posts and Comments'),
521                                 'url'   => 'contact/' . $pcid . '/posts',
522                                 'sel'   => (($active_tab == self::TAB_POSTS) ? 'active' : ''),
523                                 'title' => DI::l10n()->t('Individual Posts and Replies'),
524                                 'id'    => 'posts-tab',
525                                 'accesskey' => 'p',
526                         ],
527                         [
528                                 'label' => DI::l10n()->t('Media'),
529                                 'url'   => 'contact/' . $pcid . '/media',
530                                 'sel'   => (($active_tab == self::TAB_MEDIA) ? 'active' : ''),
531                                 'title' => DI::l10n()->t('Posts containing media objects'),
532                                 'id'    => 'media-tab',
533                                 'accesskey' => 'd',
534                         ],
535                         [
536                                 'label' => DI::l10n()->t('Contacts'),
537                                 'url'   => 'contact/' . $pcid . '/contacts',
538                                 'sel'   => (($active_tab == self::TAB_CONTACTS) ? 'active' : ''),
539                                 'title' => DI::l10n()->t('View all known contacts'),
540                                 'id'    => 'contacts-tab',
541                                 'accesskey' => 't'
542                         ],
543                 ];
544
545                 if (!empty($contact['network']) && in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && ($cid != $pcid)) {
546                         $tabs[] = [
547                                 'label' => DI::l10n()->t('Advanced'),
548                                 'url'   => 'contact/' . $cid . '/advanced/',
549                                 'sel'   => (($active_tab == self::TAB_ADVANCED) ? 'active' : ''),
550                                 'title' => DI::l10n()->t('Advanced Contact Settings'),
551                                 'id'    => 'advanced-tab',
552                                 'accesskey' => 'r'
553                         ];
554                 }
555
556                 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
557                 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
558
559                 return $tab_str;
560         }
561
562         /**
563          * Return the fields for the contact template
564          *
565          * @param array $contact Contact array
566          * @return array Template fields
567          * @throws InternalServerErrorException
568          * @throws \ImagickException
569          */
570         public static function getContactTemplateVars(array $contact): array
571         {
572                 $alt_text = '';
573
574                 if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && DI::userSession()->getLocalUserId()) {
575                         $personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], DI::userSession()->getLocalUserId());
576                         if (!empty($personal)) {
577                                 $contact['uid']  = $personal['uid'];
578                                 $contact['rel']  = $personal['rel'];
579                                 $contact['self'] = $personal['self'];
580                         }
581                 }
582
583                 if (!empty($contact['uid']) && !empty($contact['rel']) && DI::userSession()->getLocalUserId() == $contact['uid']) {
584                         switch ($contact['rel']) {
585                                 case Model\Contact::FRIEND:
586                                         $alt_text = DI::l10n()->t('Mutual Friendship');
587                                         break;
588
589                                 case Model\Contact::FOLLOWER;
590                                         $alt_text = DI::l10n()->t('is a fan of yours');
591                                         break;
592
593                                 case Model\Contact::SHARING;
594                                         $alt_text = DI::l10n()->t('you are a fan of');
595                                         break;
596
597                                 default:
598                                         break;
599                         }
600                 }
601
602                 $url = Model\Contact::magicLinkByContact($contact);
603
604                 if (strpos($url, 'contact/redir/') === 0) {
605                         $sparkle = ' class="sparkle" ';
606                 } else {
607                         $sparkle = '';
608                 }
609
610                 if ($contact['pending']) {
611                         if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
612                                 $alt_text = DI::l10n()->t('Pending outgoing contact request');
613                         } else {
614                                 $alt_text = DI::l10n()->t('Pending incoming contact request');
615                         }
616                 }
617
618                 if ($contact['self']) {
619                         $alt_text = DI::l10n()->t('This is you');
620                         $url      = $contact['url'];
621                         $sparkle  = '';
622                 }
623
624                 return [
625                         'id'           => $contact['id'],
626                         'url'          => $url,
627                         'img_hover'    => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
628                         'photo_menu'   => Model\Contact::photoMenu($contact, DI::userSession()->getLocalUserId()),
629                         'thumb'        => Model\Contact::getThumb($contact, true),
630                         'alt_text'     => $alt_text,
631                         'name'         => $contact['name'],
632                         'nick'         => $contact['nick'],
633                         'details'      => $contact['location'],
634                         'tags'         => $contact['keywords'],
635                         'about'        => $contact['about'],
636                         'account_type' => Model\Contact::getAccountType($contact['contact-type']),
637                         'sparkle'      => $sparkle,
638                         'itemurl'      => ($contact['addr'] ?? '') ?: $contact['url'],
639                         'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
640                 ];
641         }
642 }