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