]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/VCard.php
Replace deprecated use of "self" in callables
[friendica.git] / src / Content / Widget / VCard.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\Content\Widget;
23
24 use Friendica\Content\ContactSelector;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\System;
30 use Friendica\DI;
31 use Friendica\Model\Contact;
32 use Friendica\Util\Strings;
33
34 /**
35  * VCard widget
36  *
37  * @author Michael Vogel
38  */
39 class VCard
40 {
41         /**
42          * Get HTML for vcard block
43          *
44          * @template widget/vcard.tpl
45          * @return string
46          */
47         public static function getHTML(array $contact): string
48         {
49                 if (!isset($contact['network']) || !isset($contact['id'])) {
50                         Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
51                 }
52
53                 if ($contact['network'] != '') {
54                         $network_link   = Strings::formatNetworkName($contact['network'], $contact['url']);
55                         $network_avatar = ContactSelector::networkToIcon($contact['network'], $contact['url']);
56                 } else {
57                         $network_link   = '';
58                         $network_avatar = '';
59                 }
60
61                 $follow_link      = '';
62                 $unfollow_link    = '';
63                 $wallmessage_link = '';
64
65                 $photo   = Contact::getPhoto($contact);
66
67                 if (DI::userSession()->getLocalUserId()) {
68                         if ($contact['uid']) {
69                                 $id      = $contact['id'];
70                                 $rel     = $contact['rel'];
71                                 $pending = $contact['pending'];
72                         } else {
73                                 $pcontact = Contact::selectFirst([], ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $contact['uri-id'], 'deleted' => false]);
74
75                                 $id      = $pcontact['id'] ?? 0;
76                                 $rel     = $pcontact['rel'] ?? Contact::NOTHING;
77                                 $pending = $pcontact['pending'] ?? false;
78
79                                 if (!empty($pcontact) && in_array($pcontact['network'], [Protocol::MAIL, Protocol::FEED])) {
80                                         $photo = Contact::getPhoto($pcontact);
81                                 }
82                         }
83
84                         if (empty($contact['self']) && Protocol::supportsFollow($contact['network'])) {
85                                 if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
86                                         $unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1';
87                                 } elseif (!$pending) {
88                                         $follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1';
89                                 }
90                         }
91
92                         if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
93                                 $wallmessage_link = 'message/new/' . $id;
94                         }
95                 }
96
97                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
98                         '$contact'          => $contact,
99                         '$photo'            => $photo,
100                         '$url'              => Contact::magicLinkByContact($contact, $contact['url']),
101                         '$about'            => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
102                         '$xmpp'             => DI::l10n()->t('XMPP:'),
103                         '$matrix'           => DI::l10n()->t('Matrix:'),
104                         '$location'         => DI::l10n()->t('Location:'),
105                         '$network_link'     => $network_link,
106                         '$network_avatar'   => $network_avatar,
107                         '$network'          => DI::l10n()->t('Network:'),
108                         '$account_type'     => Contact::getAccountType($contact['contact-type']),
109                         '$follow'           => DI::l10n()->t('Follow'),
110                         '$follow_link'      => $follow_link,
111                         '$unfollow'         => DI::l10n()->t('Unfollow'),
112                         '$unfollow_link'    => $unfollow_link,
113                         '$wallmessage'      => DI::l10n()->t('Message'),
114                         '$wallmessage_link' => $wallmessage_link,
115                 ]);
116         }
117 }