2019-01-05 22:04:42 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @file src/Content/Widget/ContactBlock.php
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Content\Widget;
|
|
|
|
|
|
|
|
use Friendica\Content\Text\HTML;
|
|
|
|
use Friendica\Core\Hook;
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Database\DBA;
|
2020-01-18 10:50:57 -05:00
|
|
|
use Friendica\DI;
|
2019-01-05 22:04:42 -05:00
|
|
|
use Friendica\Model\Contact;
|
2019-01-06 17:08:58 -05:00
|
|
|
use Friendica\Model\User;
|
2019-01-05 22:04:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ContactBlock widget
|
|
|
|
*
|
|
|
|
* @author Hypolite Petovan
|
|
|
|
*/
|
|
|
|
class ContactBlock
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get HTML for contact block
|
|
|
|
*
|
2019-05-18 11:33:35 -04:00
|
|
|
* @template widget/contacts.tpl
|
2019-01-05 22:04:42 -05:00
|
|
|
* @hook contact_block_end (contacts=>array, output=>string)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getHTML(array $profile)
|
|
|
|
{
|
|
|
|
$o = '';
|
|
|
|
|
2020-01-18 10:50:57 -05:00
|
|
|
$shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
|
2019-01-05 22:04:42 -05:00
|
|
|
if ($shown == 0) {
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($profile['hide-friends'])) {
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
$contacts = [];
|
|
|
|
|
|
|
|
$total = DBA::count('contact', [
|
|
|
|
'uid' => $profile['uid'],
|
|
|
|
'self' => false,
|
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'archive' => false,
|
2019-05-18 11:47:39 -04:00
|
|
|
'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
|
2019-01-05 22:04:42 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
$contacts_title = L10n::t('No contacts');
|
|
|
|
|
2019-01-23 16:54:20 -05:00
|
|
|
$micropro = [];
|
|
|
|
|
|
|
|
if ($total) {
|
2019-01-06 17:08:58 -05:00
|
|
|
// Only show followed for personal accounts, followers for pages
|
2019-10-16 08:35:14 -04:00
|
|
|
if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
|
2019-01-06 17:08:58 -05:00
|
|
|
$rel = [Contact::SHARING, Contact::FRIEND];
|
2019-03-04 08:40:53 -05:00
|
|
|
} else {
|
|
|
|
$rel = [Contact::FOLLOWER, Contact::FRIEND];
|
2019-01-06 17:08:58 -05:00
|
|
|
}
|
|
|
|
|
2019-01-05 22:04:42 -05:00
|
|
|
$contact_ids_stmt = DBA::select('contact', ['id'], [
|
|
|
|
'uid' => $profile['uid'],
|
|
|
|
'self' => false,
|
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'archive' => false,
|
2019-01-06 17:08:58 -05:00
|
|
|
'rel' => $rel,
|
2019-07-01 14:00:55 -04:00
|
|
|
'network' => Protocol::FEDERATED,
|
2019-01-05 22:04:42 -05:00
|
|
|
], ['limit' => $shown]);
|
|
|
|
|
|
|
|
if (DBA::isResult($contact_ids_stmt)) {
|
|
|
|
$contact_ids = [];
|
|
|
|
while($contact = DBA::fetch($contact_ids_stmt)) {
|
|
|
|
$contact_ids[] = $contact["id"];
|
|
|
|
}
|
|
|
|
|
|
|
|
$contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
|
|
|
|
|
|
|
|
if (DBA::isResult($contacts_stmt)) {
|
|
|
|
$contacts_title = L10n::tt('%d Contact', '%d Contacts', $total);
|
|
|
|
$micropro = [];
|
|
|
|
|
|
|
|
while ($contact = DBA::fetch($contacts_stmt)) {
|
|
|
|
$contacts[] = $contact;
|
|
|
|
$micropro[] = HTML::micropro($contact, true, 'mpfriend');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBA::close($contacts_stmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBA::close($contact_ids_stmt);
|
|
|
|
}
|
|
|
|
|
2019-05-18 11:33:35 -04:00
|
|
|
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
|
2019-01-05 22:04:42 -05:00
|
|
|
$o = Renderer::replaceMacros($tpl, [
|
|
|
|
'$contacts' => $contacts_title,
|
|
|
|
'$nickname' => $profile['nickname'],
|
|
|
|
'$viewcontacts' => L10n::t('View Contacts'),
|
|
|
|
'$micropro' => $micropro,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$arr = ['contacts' => $contacts, 'output' => $o];
|
|
|
|
|
|
|
|
Hook::callAll('contact_block_end', $arr);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|