X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FWidget%2FContactBlock.php;h=751aa921784edb873b26442ac16e3b531934b2d6;hb=58215e56c329f6cbcbe10575bb0b9ef709b2f093;hp=ef152f900846fbfcaa7061475eb37499a29e94cc;hpb=4c4ed63dca13cc0382af9020e69980c63f988b47;p=friendica.git diff --git a/src/Content/Widget/ContactBlock.php b/src/Content/Widget/ContactBlock.php index ef152f9008..751aa92178 100644 --- a/src/Content/Widget/ContactBlock.php +++ b/src/Content/Widget/ContactBlock.php @@ -1,18 +1,32 @@ . + * */ 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; @@ -30,11 +44,17 @@ class ContactBlock * @hook contact_block_end (contacts=>array, output=>string) * @return string */ - public static function getHTML(array $profile) + public static function getHTML(array $profile, int $visitor_uid = null) { $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; } @@ -52,22 +72,23 @@ class ContactBlock 'pending' => false, 'hidden' => false, 'archive' => false, + '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'); $micropro = []; if ($total) { // Only show followed for personal accounts, followers for pages - if (defaults($profile, 'account-type', User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) { + if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) { $rel = [Contact::SHARING, Contact::FRIEND]; } else { $rel = [Contact::FOLLOWER, Contact::FRIEND]; } - $contact_ids_stmt = DBA::select('contact', ['id'], [ + $personal_contacts = DBA::selectToArray('contact', ['uri-id'], [ 'uid' => $profile['uid'], 'self' => false, 'blocked' => false, @@ -78,16 +99,13 @@ class ContactBlock 'network' => Protocol::FEDERATED, ], ['limit' => $shown]); - if (DBA::isResult($contact_ids_stmt)) { - $contact_ids = []; - while($contact = DBA::fetch($contact_ids_stmt)) { - $contact_ids[] = $contact["id"]; - } + $contact_uriids = array_column($personal_contacts, 'uri-id'); - $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]); + 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)) { @@ -98,15 +116,13 @@ class ContactBlock DBA::close($contacts_stmt); } - - DBA::close($contact_ids_stmt); } $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, ]);