X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FWidget%2FContactBlock.php;h=e206dbcb4e349878ceca518b3e9566677417d009;hb=2b1fc4b5615b0bc4a003ab941e4762e92eea4aa3;hp=12cd4cd87d2055a08917d624b4b14e405222a211;hpb=1f98fdfda6a3e2b2f4f9065e690087a325678c5e;p=friendica.git diff --git a/src/Content/Widget/ContactBlock.php b/src/Content/Widget/ContactBlock.php index 12cd4cd87d..e206dbcb4e 100644 --- a/src/Content/Widget/ContactBlock.php +++ b/src/Content/Widget/ContactBlock.php @@ -1,19 +1,34 @@ . + * */ namespace Friendica\Content\Widget; use Friendica\Content\Text\HTML; use Friendica\Core\Hook; -use Friendica\Core\L10n; -use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; +use Friendica\Model\User; /** * ContactBlock widget @@ -25,15 +40,21 @@ class ContactBlock /** * Get HTML for contact block * - * @template contact_block.tpl + * @template widget/contacts.tpl * @hook contact_block_end (contacts=>array, output=>string) - * @return string + * @return string Formatted HTML code or empty string */ - public static function getHTML(array $profile) + public static function getHTML(array $profile, int $visitor_uid = null): string { $o = ''; - $shown = PConfig::get($profile['uid'], 'system', 'display_friend_count', 24); + if (is_null($visitor_uid) || ($visitor_uid == $profile['uid'])) { + $contact_uid = $profile['uid']; + } else { + $contact_uid = 0; + } + + $shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24); if ($shown == 0) { return $o; } @@ -45,41 +66,48 @@ class ContactBlock $contacts = []; $total = DBA::count('contact', [ - 'uid' => $profile['uid'], - 'self' => false, + 'uid' => $profile['uid'], + 'self' => false, 'blocked' => false, 'pending' => false, - 'hidden' => false, + 'hidden' => false, 'archive' => false, - 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA], + 'failed' => false, + 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED], ]); - $contacts_title = L10n::t('No contacts'); + $contacts_title = DI::l10n()->t('No contacts'); - if (!$total) { - $micropro = []; - } else { - $contact_ids_stmt = DBA::select('contact', ['id'], [ - 'uid' => $profile['uid'], - 'self' => false, + $micropro = []; + + if ($total) { + // Only show followed for personal accounts, followers for pages + if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) { + $rel = [Contact::SHARING, Contact::FRIEND]; + } else { + $rel = [Contact::FOLLOWER, Contact::FRIEND]; + } + + $personal_contacts = DBA::selectToArray('contact', ['uri-id'], [ + 'uid' => $profile['uid'], + 'self' => false, 'blocked' => false, 'pending' => false, - 'hidden' => false, + 'hidden' => false, 'archive' => false, - 'rel' => [Contact::FOLLOWER, Contact::FRIEND], - 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA], - ], ['limit' => $shown]); - - if (DBA::isResult($contact_ids_stmt)) { - $contact_ids = []; - while($contact = DBA::fetch($contact_ids_stmt)) { - $contact_ids[] = $contact["id"]; - } + 'rel' => $rel, + 'network' => Protocol::FEDERATED, + ], [ + 'limit' => $shown, + ]); - $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]); + $contact_uriids = array_column($personal_contacts, 'uri-id'); + + if (!empty($contact_uriids)) { + $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'avatar', 'network'], ['uri-id' => $contact_uriids, 'uid' => $contact_uid]); if (DBA::isResult($contacts_stmt)) { - $contacts_title = L10n::tt('%d Contact', '%d Contacts', $total); + $contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total); $micropro = []; while ($contact = DBA::fetch($contacts_stmt)) { @@ -90,15 +118,13 @@ class ContactBlock DBA::close($contacts_stmt); } - - DBA::close($contact_ids_stmt); } - $tpl = Renderer::getMarkupTemplate('contact_block.tpl'); + $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl'); $o = Renderer::replaceMacros($tpl, [ '$contacts' => $contacts_title, '$nickname' => $profile['nickname'], - '$viewcontacts' => L10n::t('View Contacts'), + '$viewcontacts' => DI::l10n()->t('View Contacts'), '$micropro' => $micropro, ]);