]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/VCard.php
a7d7d8cbd2e7fa3d41d2b1e68b8d668156e150e2
[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\Protocol;
26 use Friendica\Core\Renderer;
27 use Friendica\DI;
28 use Friendica\Model\Contact;
29 use Friendica\Util\Strings;
30
31 /**
32  * VCard widget
33  *
34  * @author Michael Vogel
35  */
36 class VCard
37 {
38         /**
39          * Get HTML for vcard block
40          *
41          * @template widget/vcard.tpl
42          * @return string
43          */
44         public static function getHTML(array $contact)
45         {
46                 if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
47                         $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
48                 } else {
49                         $network_link = '';
50                 }
51
52                 $follow_link = '';
53                 $unfollow_link = '';
54                 $wallmessage_link = '';
55
56                 if (local_user()) {
57                         if ($contact['uid']) {
58                                 $id      = $contact['id'];
59                                 $rel     = $contact['rel'];
60                                 $pending = $contact['pending'];
61                         } else {
62                                 $pcontact = Contact::selectFirst(['id', 'rel', 'pending'], ['uid' => local_user(), 'uri-id' => $contact['uri-id']]);
63                                 $id      = $pcontact['id'] ?? 0;
64                                 $rel     = $pcontact['rel'] ?? Contact::NOTHING;
65                                 $pending = $pcontact['pending'] ?? false;
66                         }
67
68                         if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
69                                 if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
70                                         $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
71                                 } elseif(!$pending) {
72                                         $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
73                                 }
74                         }
75
76                         if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
77                                 $wallmessage_link = 'message/new/' . $id;
78                         }
79                 }
80
81                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
82                         '$contact'          => $contact,
83                         '$photo'            => Contact::getPhoto($contact),
84                         '$url'              => Contact::magicLinkByContact($contact, $contact['url']),
85                         '$about'            => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
86                         '$xmpp'             => DI::l10n()->t('XMPP:'),
87                         '$location'         => DI::l10n()->t('Location:'),
88                         '$network_link'     => $network_link,
89                         '$network'          => DI::l10n()->t('Network:'),
90                         '$account_type'     => Contact::getAccountType($contact),
91                         '$follow'           => DI::l10n()->t('Follow'),
92                         '$follow_link'      => $follow_link,
93                         '$unfollow'         => DI::l10n()->t('Unfollow'),
94                         '$unfollow_link'    => $unfollow_link,
95                         '$wallmessage'      => DI::l10n()->t('Message'),
96                         '$wallmessage_link' => $wallmessage_link,
97                 ]);
98         }
99 }