]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/VCard.php
Many more app-variables removed
[friendica.git] / src / Content / Widget / VCard.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Content\Widget;
23
24 use Friendica\Content\Text\BBCode;
25 use Friendica\Core\Logger;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\System;
29 use Friendica\DI;
30 use Friendica\Model\Contact;
31 use Friendica\Util\Strings;
32
33 /**
34  * VCard widget
35  *
36  * @author Michael Vogel
37  */
38 class VCard
39 {
40         /**
41          * Get HTML for vcard block
42          *
43          * @template widget/vcard.tpl
44          * @return string
45          */
46         public static function getHTML(array $contact)
47         {
48                 if (!isset($contact['network']) || !isset($contact['id'])) {
49                         Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
50                 }
51
52                 if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
53                         $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
54                 } else {
55                         $network_link = '';
56                 }
57
58                 $follow_link      = '';
59                 $unfollow_link    = '';
60                 $wallmessage_link = '';
61
62                 if (local_user()) {
63                         if ($contact['uid']) {
64                                 $id      = $contact['id'];
65                                 $rel     = $contact['rel'];
66                                 $pending = $contact['pending'];
67                         } else {
68                                 $pcontact = Contact::selectFirst(['id', 'rel', 'pending'], ['uid' => local_user(), 'uri-id' => $contact['uri-id']]);
69
70                                 $id      = $pcontact['id'] ?? 0;
71                                 $rel     = $pcontact['rel'] ?? Contact::NOTHING;
72                                 $pending = $pcontact['pending'] ?? false;
73                         }
74
75                         if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
76                                 if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
77                                         $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
78                                 } elseif (!$pending) {
79                                         $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
80                                 }
81                         }
82
83                         if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
84                                 $wallmessage_link = 'message/new/' . $id;
85                         }
86                 }
87
88                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
89                         '$contact'          => $contact,
90                         '$photo'            => Contact::getPhoto($contact),
91                         '$url'              => Contact::magicLinkByContact($contact, $contact['url']),
92                         '$about'            => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
93                         '$xmpp'             => DI::l10n()->t('XMPP:'),
94                         '$location'         => DI::l10n()->t('Location:'),
95                         '$network_link'     => $network_link,
96                         '$network'          => DI::l10n()->t('Network:'),
97                         '$account_type'     => Contact::getAccountType($contact),
98                         '$follow'           => DI::l10n()->t('Follow'),
99                         '$follow_link'      => $follow_link,
100                         '$unfollow'         => DI::l10n()->t('Unfollow'),
101                         '$unfollow_link'    => $unfollow_link,
102                         '$wallmessage'      => DI::l10n()->t('Message'),
103                         '$wallmessage_link' => $wallmessage_link,
104                 ]);
105         }
106 }