3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Content\Widget;
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;
31 use Friendica\Model\Contact;
32 use Friendica\Util\Network;
33 use Friendica\Util\Strings;
38 * @author Michael Vogel
43 * Get HTML for vcard block
45 * @template widget/vcard.tpl
48 public static function getHTML(array $contact): string
50 if (!isset($contact['network']) || !isset($contact['id'])) {
51 Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
54 if (!Network::isValidHttpUrl($contact['url']) && Network::isValidHttpUrl($contact['alias'])) {
55 $contact_url = $contact['alias'];
57 $contact_url = $contact['url'];
60 if ($contact['network'] != '') {
61 $network_link = Strings::formatNetworkName($contact['network'], $contact_url);
62 $network_avatar = ContactSelector::networkToIcon($contact['network'], $contact_url);
70 $wallmessage_link = '';
73 $photo = Contact::getPhoto($contact);
75 if (DI::userSession()->getLocalUserId()) {
76 if ($contact['uid']) {
78 $rel = $contact['rel'];
79 $pending = $contact['pending'];
81 $pcontact = Contact::selectFirst([], ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $contact['uri-id'], 'deleted' => false]);
83 $id = $pcontact['id'] ?? 0;
84 $rel = $pcontact['rel'] ?? Contact::NOTHING;
85 $pending = $pcontact['pending'] ?? false;
87 if (!empty($pcontact) && in_array($pcontact['network'], [Protocol::MAIL, Protocol::FEED])) {
88 $photo = Contact::getPhoto($pcontact);
92 if (empty($contact['self']) && Protocol::supportsFollow($contact['network'])) {
93 if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
94 $unfollow_link = 'contact/unfollow?url=' . urlencode($contact_url) . '&auto=1';
95 } elseif (!$pending) {
96 $follow_link = 'contact/follow?url=' . urlencode($contact_url) . '&auto=1';
100 if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
101 $wallmessage_link = 'message/new/' . $id;
104 if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
105 $showgroup_link = 'network/group/' . $id;
109 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
110 '$contact' => $contact,
112 '$url' => Contact::magicLinkByContact($contact, $contact_url),
113 '$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
114 '$xmpp' => DI::l10n()->t('XMPP:'),
115 '$matrix' => DI::l10n()->t('Matrix:'),
116 '$location' => DI::l10n()->t('Location:'),
117 '$network_link' => $network_link,
118 '$network_avatar' => $network_avatar,
119 '$network' => DI::l10n()->t('Network:'),
120 '$account_type' => Contact::getAccountType($contact['contact-type']),
121 '$follow' => DI::l10n()->t('Follow'),
122 '$follow_link' => $follow_link,
123 '$unfollow' => DI::l10n()->t('Unfollow'),
124 '$unfollow_link' => $unfollow_link,
125 '$wallmessage' => DI::l10n()->t('Message'),
126 '$wallmessage_link' => $wallmessage_link,
127 '$mention' => DI::l10n()->t('Mention'),
128 '$posttogroup' => DI::l10n()->t('Post to group'),
129 '$showgroup' => DI::l10n()->t('View group'),
130 '$showgroup_link' => $showgroup_link,