. * */ namespace Friendica\Module\Profile; use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model; use Friendica\Module; use Friendica\Network\HTTPException; class Contacts extends Module\BaseProfile { public static function content(array $parameters = []) { if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); } $a = DI::app(); $nickname = $parameters['nickname']; $type = $parameters['type'] ?? 'all'; Model\Profile::load($a, $nickname); if (empty($a->profile)) { throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); } $is_owner = $a->profile['uid'] == local_user(); if (!empty($a->profile['hide-friends']) && !$is_owner) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); } Nav::setSelected('home'); $o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname); $tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $a->profile['uid'] != local_user()); $condition = [ 'uid' => $a->profile['uid'], 'blocked' => false, 'pending' => false, 'hidden' => false, 'archive' => false, 'self' => false, 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED] ]; switch ($type) { case 'followers': $condition['rel'] = [Model\Contact::FOLLOWER, Model\Contact::FRIEND]; break; case 'following': $condition['rel'] = [Model\Contact::SHARING, Model\Contact::FRIEND]; break; case 'mutuals': $condition['rel'] = Model\Contact::FRIEND; break; } $total = DBA::count('contact', $condition); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30); $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $contacts = array_map( [Module\Contact::class, 'getContactTemplateVars'], Model\Contact::selectToArray([], $condition, $params) ); $desc = ''; switch ($type) { case 'followers': $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total); break; case 'following': $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total); break; case 'mutuals': $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); $desc = DI::l10n()->t( 'These contacts both follow and are followed by %s.', htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8') ); break; case 'all': default: $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total); break; } $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl'); $o .= Renderer::replaceMacros($tpl, [ '$title' => $title, '$desc' => $desc, '$tabs' => $tabs, '$noresult_label' => DI::l10n()->t('No contacts.'), '$contacts' => $contacts, '$paginate' => $pager->renderFull($total), ]); return $o; } }