<?php
-
-/*
- * @file src/Content/Widget/ContactBlock.php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @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;
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;
* @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 = '';
+ 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;
'pending' => false,
'hidden' => false,
'archive' => false,
+ 'failed' => false,
'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
]);
$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,
'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)) {
DBA::close($contacts_stmt);
}
-
- DBA::close($contact_ids_stmt);
}
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');