2021-07-23 14:39:37 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 15:36:24 +01:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2021-07-23 14:39:37 +02:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Content\Widget;
|
|
|
|
|
2021-07-24 14:21:33 +02:00
|
|
|
use Friendica\Content\ContactSelector;
|
2021-07-23 14:39:37 +02:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2021-07-24 12:09:39 +02:00
|
|
|
use Friendica\Core\Logger;
|
2021-07-23 14:39:37 +02:00
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Renderer;
|
2021-07-24 12:09:39 +02:00
|
|
|
use Friendica\Core\System;
|
2021-07-23 14:39:37 +02:00
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Contact;
|
2023-06-18 18:49:38 +02:00
|
|
|
use Friendica\Util\Network;
|
2021-07-23 14:39:37 +02:00
|
|
|
use Friendica\Util\Strings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VCard widget
|
|
|
|
*
|
|
|
|
* @author Michael Vogel
|
|
|
|
*/
|
|
|
|
class VCard
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get HTML for vcard block
|
|
|
|
*
|
|
|
|
* @template widget/vcard.tpl
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-09-11 07:04:13 +02:00
|
|
|
public static function getHTML(array $contact): string
|
2021-07-23 14:39:37 +02:00
|
|
|
{
|
2021-07-24 12:09:39 +02:00
|
|
|
if (!isset($contact['network']) || !isset($contact['id'])) {
|
|
|
|
Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
|
|
|
|
}
|
|
|
|
|
2023-06-18 18:49:38 +02:00
|
|
|
if (!Network::isValidHttpUrl($contact['url']) && Network::isValidHttpUrl($contact['alias'])) {
|
2023-06-23 23:05:45 +02:00
|
|
|
$contact_url = $contact['alias'];
|
2023-06-18 18:49:38 +02:00
|
|
|
} else {
|
2023-06-23 23:05:45 +02:00
|
|
|
$contact_url = $contact['url'];
|
2023-06-18 18:49:38 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 14:21:33 +02:00
|
|
|
if ($contact['network'] != '') {
|
2023-06-23 23:05:45 +02:00
|
|
|
$network_link = Strings::formatNetworkName($contact['network'], $contact_url);
|
|
|
|
$network_avatar = ContactSelector::networkToIcon($contact['network'], $contact_url);
|
2021-07-23 14:39:37 +02:00
|
|
|
} else {
|
2021-07-24 14:21:33 +02:00
|
|
|
$network_link = '';
|
|
|
|
$network_avatar = '';
|
2021-07-23 14:39:37 +02:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:08:41 +02:00
|
|
|
$follow_link = '';
|
|
|
|
$unfollow_link = '';
|
2021-07-23 14:39:37 +02:00
|
|
|
$wallmessage_link = '';
|
|
|
|
|
2022-06-04 09:57:11 +02:00
|
|
|
$photo = Contact::getPhoto($contact);
|
|
|
|
|
2022-10-20 21:22:47 +02:00
|
|
|
if (DI::userSession()->getLocalUserId()) {
|
2021-07-23 14:39:37 +02:00
|
|
|
if ($contact['uid']) {
|
|
|
|
$id = $contact['id'];
|
|
|
|
$rel = $contact['rel'];
|
|
|
|
$pending = $contact['pending'];
|
|
|
|
} else {
|
2022-10-30 21:40:21 +01:00
|
|
|
$pcontact = Contact::selectFirst([], ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $contact['uri-id'], 'deleted' => false]);
|
2021-07-23 15:08:41 +02:00
|
|
|
|
2021-07-23 14:39:37 +02:00
|
|
|
$id = $pcontact['id'] ?? 0;
|
|
|
|
$rel = $pcontact['rel'] ?? Contact::NOTHING;
|
|
|
|
$pending = $pcontact['pending'] ?? false;
|
2022-06-04 09:57:11 +02:00
|
|
|
|
|
|
|
if (!empty($pcontact) && in_array($pcontact['network'], [Protocol::MAIL, Protocol::FEED])) {
|
|
|
|
$photo = Contact::getPhoto($pcontact);
|
|
|
|
}
|
2021-07-23 14:39:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 15:45:32 +01:00
|
|
|
if (empty($contact['self']) && Protocol::supportsFollow($contact['network'])) {
|
2021-07-23 14:39:37 +02:00
|
|
|
if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
|
2023-06-23 23:05:45 +02:00
|
|
|
$unfollow_link = 'contact/unfollow?url=' . urlencode($contact_url) . '&auto=1';
|
2021-07-23 15:09:12 +02:00
|
|
|
} elseif (!$pending) {
|
2023-06-23 23:05:45 +02:00
|
|
|
$follow_link = 'contact/follow?url=' . urlencode($contact_url) . '&auto=1';
|
2021-07-23 14:39:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
|
|
|
|
$wallmessage_link = 'message/new/' . $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
|
|
|
|
'$contact' => $contact,
|
2022-06-04 09:57:11 +02:00
|
|
|
'$photo' => $photo,
|
2023-06-23 23:05:45 +02:00
|
|
|
'$url' => Contact::magicLinkByContact($contact, $contact_url),
|
2021-07-23 14:39:37 +02:00
|
|
|
'$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
|
|
|
|
'$xmpp' => DI::l10n()->t('XMPP:'),
|
2021-08-09 03:39:09 +02:00
|
|
|
'$matrix' => DI::l10n()->t('Matrix:'),
|
2021-07-23 14:39:37 +02:00
|
|
|
'$location' => DI::l10n()->t('Location:'),
|
|
|
|
'$network_link' => $network_link,
|
2021-07-24 14:21:33 +02:00
|
|
|
'$network_avatar' => $network_avatar,
|
2021-07-23 14:39:37 +02:00
|
|
|
'$network' => DI::l10n()->t('Network:'),
|
2022-02-09 07:52:16 +01:00
|
|
|
'$account_type' => Contact::getAccountType($contact['contact-type']),
|
2021-07-23 14:39:37 +02:00
|
|
|
'$follow' => DI::l10n()->t('Follow'),
|
|
|
|
'$follow_link' => $follow_link,
|
|
|
|
'$unfollow' => DI::l10n()->t('Unfollow'),
|
|
|
|
'$unfollow_link' => $unfollow_link,
|
|
|
|
'$wallmessage' => DI::l10n()->t('Message'),
|
|
|
|
'$wallmessage_link' => $wallmessage_link,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|