3 * @copyright Copyright (C) 2010-2021, 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\Strings;
37 * @author Michael Vogel
42 * Get HTML for vcard block
44 * @template widget/vcard.tpl
47 public static function getHTML(array $contact)
49 if (!isset($contact['network']) || !isset($contact['id'])) {
50 Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
53 if ($contact['network'] != '') {
54 $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
55 $network_avatar = ContactSelector::networkToIcon($contact['network'], $contact['url']);
63 $wallmessage_link = '';
66 if ($contact['uid']) {
68 $rel = $contact['rel'];
69 $pending = $contact['pending'];
71 $pcontact = Contact::selectFirst(['id', 'rel', 'pending'], ['uid' => local_user(), 'uri-id' => $contact['uri-id']]);
73 $id = $pcontact['id'] ?? 0;
74 $rel = $pcontact['rel'] ?? Contact::NOTHING;
75 $pending = $pcontact['pending'] ?? false;
78 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
79 if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
80 $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
81 } elseif (!$pending) {
82 $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
86 if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
87 $wallmessage_link = 'message/new/' . $id;
91 return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
92 '$contact' => $contact,
93 '$photo' => Contact::getPhoto($contact),
94 '$url' => Contact::magicLinkByContact($contact, $contact['url']),
95 '$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
96 '$xmpp' => DI::l10n()->t('XMPP:'),
97 '$location' => DI::l10n()->t('Location:'),
98 '$network_link' => $network_link,
99 '$network_avatar' => $network_avatar,
100 '$network' => DI::l10n()->t('Network:'),
101 '$account_type' => Contact::getAccountType($contact),
102 '$follow' => DI::l10n()->t('Follow'),
103 '$follow_link' => $follow_link,
104 '$unfollow' => DI::l10n()->t('Unfollow'),
105 '$unfollow_link' => $unfollow_link,
106 '$wallmessage' => DI::l10n()->t('Message'),
107 '$wallmessage_link' => $wallmessage_link,