2019-01-06 03:04:42 +00:00
|
|
|
<?php
|
2020-02-09 15:34:23 +00:00
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 15:34:23 +00: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/>.
|
|
|
|
*
|
2019-01-06 03:04:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Content\Widget;
|
|
|
|
|
|
|
|
use Friendica\Content\Text\HTML;
|
|
|
|
use Friendica\Core\Hook;
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Database\DBA;
|
2020-01-18 15:50:57 +00:00
|
|
|
use Friendica\DI;
|
2019-01-06 03:04:42 +00:00
|
|
|
use Friendica\Model\Contact;
|
2019-01-06 22:08:58 +00:00
|
|
|
use Friendica\Model\User;
|
2019-01-06 03:04:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ContactBlock widget
|
|
|
|
*
|
|
|
|
* @author Hypolite Petovan
|
|
|
|
*/
|
|
|
|
class ContactBlock
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get HTML for contact block
|
|
|
|
*
|
2019-05-18 15:33:35 +00:00
|
|
|
* @template widget/contacts.tpl
|
2019-01-06 03:04:42 +00:00
|
|
|
* @hook contact_block_end (contacts=>array, output=>string)
|
2022-09-11 05:04:13 +00:00
|
|
|
* @return string Formatted HTML code or empty string
|
2019-01-06 03:04:42 +00:00
|
|
|
*/
|
2022-09-11 05:04:13 +00:00
|
|
|
public static function getHTML(array $profile, int $visitor_uid = null): string
|
2019-01-06 03:04:42 +00:00
|
|
|
{
|
|
|
|
$o = '';
|
|
|
|
|
2021-09-19 10:06:42 +00:00
|
|
|
if (is_null($visitor_uid) || ($visitor_uid == $profile['uid'])) {
|
|
|
|
$contact_uid = $profile['uid'];
|
|
|
|
} else {
|
|
|
|
$contact_uid = 0;
|
|
|
|
}
|
|
|
|
|
2020-01-18 15:50:57 +00:00
|
|
|
$shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
|
2019-01-06 03:04:42 +00:00
|
|
|
if ($shown == 0) {
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($profile['hide-friends'])) {
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
$contacts = [];
|
|
|
|
|
|
|
|
$total = DBA::count('contact', [
|
2022-09-11 05:04:13 +00:00
|
|
|
'uid' => $profile['uid'],
|
|
|
|
'self' => false,
|
2019-01-06 03:04:42 +00:00
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
2022-09-11 05:04:13 +00:00
|
|
|
'hidden' => false,
|
2019-01-06 03:04:42 +00:00
|
|
|
'archive' => false,
|
2022-09-11 05:04:13 +00:00
|
|
|
'failed' => false,
|
2019-05-18 15:47:39 +00:00
|
|
|
'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
|
2019-01-06 03:04:42 +00:00
|
|
|
]);
|
|
|
|
|
2020-01-18 19:52:34 +00:00
|
|
|
$contacts_title = DI::l10n()->t('No contacts');
|
2019-01-06 03:04:42 +00:00
|
|
|
|
2019-01-23 21:54:20 +00:00
|
|
|
$micropro = [];
|
|
|
|
|
|
|
|
if ($total) {
|
2019-01-06 22:08:58 +00:00
|
|
|
// Only show followed for personal accounts, followers for pages
|
2019-10-16 12:35:14 +00:00
|
|
|
if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
|
2019-01-06 22:08:58 +00:00
|
|
|
$rel = [Contact::SHARING, Contact::FRIEND];
|
2019-03-04 13:40:53 +00:00
|
|
|
} else {
|
|
|
|
$rel = [Contact::FOLLOWER, Contact::FRIEND];
|
2019-01-06 22:08:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 10:06:42 +00:00
|
|
|
$personal_contacts = DBA::selectToArray('contact', ['uri-id'], [
|
2022-09-11 05:04:13 +00:00
|
|
|
'uid' => $profile['uid'],
|
|
|
|
'self' => false,
|
2019-01-06 03:04:42 +00:00
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
2022-09-11 05:04:13 +00:00
|
|
|
'hidden' => false,
|
2019-01-06 03:04:42 +00:00
|
|
|
'archive' => false,
|
2022-09-11 05:04:13 +00:00
|
|
|
'rel' => $rel,
|
2019-07-01 18:00:55 +00:00
|
|
|
'network' => Protocol::FEDERATED,
|
2022-09-11 05:04:13 +00:00
|
|
|
], [
|
|
|
|
'limit' => $shown,
|
|
|
|
]);
|
2019-01-06 03:04:42 +00:00
|
|
|
|
2021-09-19 17:56:44 +00:00
|
|
|
$contact_uriids = array_column($personal_contacts, 'uri-id');
|
2019-01-06 03:04:42 +00:00
|
|
|
|
2021-09-19 17:56:44 +00:00
|
|
|
if (!empty($contact_uriids)) {
|
|
|
|
$contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'avatar', 'network'], ['uri-id' => $contact_uriids, 'uid' => $contact_uid]);
|
2019-01-06 03:04:42 +00:00
|
|
|
|
|
|
|
if (DBA::isResult($contacts_stmt)) {
|
2020-01-18 19:53:01 +00:00
|
|
|
$contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
|
2019-01-06 03:04:42 +00:00
|
|
|
$micropro = [];
|
|
|
|
|
|
|
|
while ($contact = DBA::fetch($contacts_stmt)) {
|
|
|
|
$contacts[] = $contact;
|
|
|
|
$micropro[] = HTML::micropro($contact, true, 'mpfriend');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBA::close($contacts_stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 15:33:35 +00:00
|
|
|
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
|
2019-01-06 03:04:42 +00:00
|
|
|
$o = Renderer::replaceMacros($tpl, [
|
|
|
|
'$contacts' => $contacts_title,
|
|
|
|
'$nickname' => $profile['nickname'],
|
2020-01-18 19:52:34 +00:00
|
|
|
'$viewcontacts' => DI::l10n()->t('View Contacts'),
|
2019-01-06 03:04:42 +00:00
|
|
|
'$micropro' => $micropro,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$arr = ['contacts' => $contacts, 'output' => $o];
|
|
|
|
|
|
|
|
Hook::callAll('contact_block_end', $arr);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|