<commit_before><?php

namespace Friendica\Module\Profile;

use Friendica\BaseModule;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\Proxy as ProxyUtils;

class Contacts extends BaseModule
{
	public static function content()
	{
		if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
			throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
		}

		$a = self::getApp();

		//@TODO: Get value from router parameters
		$nickname = $a->argv[1];
		$type = defaults($a->argv, 3, 'all');

		Nav::setSelected('home');

		$user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
		if (!DBA::isResult($user)) {
			throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
		}

		$a->data['user'] = $user;
		$a->profile_uid  = $user['uid'];

		Profile::load($a, $nickname);

		$is_owner = $a->profile['profile_uid'] == local_user();

		// tabs
		$o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);

		if (!count($a->profile) || $a->profile['hide-friends']) {
			notice(L10n::t('Permission denied.') . EOL);
			return $o;
		}

		$condition = [
			'uid'     => $a->profile['uid'],
			'blocked' => false,
			'pending' => false,
			'hidden'  => false,
			'archive' => false,
			'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
		];

		switch ($type) {
			case 'followers': $condition['rel'] = [1, 3]; break;
			case 'following': $condition['rel'] = [2, 3]; break;
			case 'mutuals': $condition['rel'] = 3; break;
		}

		$total = DBA::count('contact', $condition);

		$pager = new Pager($a->query_string);

		$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

		$contacts_stmt = DBA::select('contact', [], $condition, $params);

		if (!DBA::isResult($contacts_stmt)) {
			info(L10n::t('No contacts.') . EOL);
			return $o;
		}

		$contacts = [];

		while ($contact = DBA::fetch($contacts_stmt)) {
			/// @TODO This triggers an E_NOTICE if 'self' is not there
			if ($contact['self']) {
				continue;
			}

			$contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);

			$contacts[] = [
				'id'           => $contact['id'],
				'img_hover'    => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
				'photo_menu'   => Contact::photoMenu($contact),
				'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
				'name'         => substr($contact_details['name'], 0, 20),
				'username'     => $contact_details['name'],<commit_msg>Remove obsolete TODO comment in Module\Profile\Contacts<commit_after><?php

namespace Friendica\Module\Profile;

use Friendica\BaseModule;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\Proxy as ProxyUtils;

class Contacts extends BaseModule
{
	public static function content()
	{
		if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
			throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
		}

		$a = self::getApp();

		//@TODO: Get value from router parameters
		$nickname = $a->argv[1];
		$type = defaults($a->argv, 3, 'all');

		Nav::setSelected('home');

		$user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
		if (!DBA::isResult($user)) {
			throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
		}

		$a->data['user'] = $user;
		$a->profile_uid  = $user['uid'];

		Profile::load($a, $nickname);

		$is_owner = $a->profile['profile_uid'] == local_user();

		// tabs
		$o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);

		if (!count($a->profile) || $a->profile['hide-friends']) {
			notice(L10n::t('Permission denied.') . EOL);
			return $o;
		}

		$condition = [
			'uid'     => $a->profile['uid'],
			'blocked' => false,
			'pending' => false,
			'hidden'  => false,
			'archive' => false,
			'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
		];

		switch ($type) {
			case 'followers': $condition['rel'] = [1, 3]; break;
			case 'following': $condition['rel'] = [2, 3]; break;
			case 'mutuals': $condition['rel'] = 3; break;
		}

		$total = DBA::count('contact', $condition);

		$pager = new Pager($a->query_string);

		$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

		$contacts_stmt = DBA::select('contact', [], $condition, $params);

		if (!DBA::isResult($contacts_stmt)) {
			info(L10n::t('No contacts.') . EOL);
			return $o;
		}

		$contacts = [];

		while ($contact = DBA::fetch($contacts_stmt)) {
			if ($contact['self']) {
				continue;
			}

			$contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);

			$contacts[] = [
				'id'           => $contact['id'],
				'img_hover'    => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
				'photo_menu'   => Contact::photoMenu($contact),
				'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
				'name'         => substr($contact_details['name'], 0, 20),
				'username'     => $contact_details['name'],
{'fraction_non_alphanumeric': 0.2063764141241001, 'fraction_numerical': 0.0075419952005485085, 'mean_word_length': 4.458372310570627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246307', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2014, 'n_words': 396}