3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Content\ContactSelector;
7 use Friendica\Content\Pager;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
11 use Friendica\Network\HTTPException;
12 use Friendica\Util\Proxy as ProxyUtils;
15 * This module shows all public friends of the selected contact
17 class AllFriends extends BaseModule
19 public static function content()
21 $app = self::getApp();
24 throw new HTTPException\ForbiddenException();
29 // @TODO: Replace with parameter from router
31 $cid = intval($app->argv[1]);
35 throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
38 $uid = $app->user['uid'];
40 $contact = Model\Contact::getContactForUser($cid, local_user(), ['name', 'url', 'photo', 'uid', 'id']);
42 if (empty($contact)) {
43 throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
46 $app->page['aside'] = "";
47 Model\Profile::load($app, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
49 $total = Model\GContact::countAllFriends(local_user(), $cid);
51 $pager = new Pager($app->query_string);
53 $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
54 if (empty($friends)) {
55 return L10n::t('No friends to display.');
61 foreach ($friends as $friend) {
62 //get further details of the contact
63 $contactDetails = Model\Contact::getDetailsByURL($friend['url'], $uid, $friend);
66 // $friend[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photoMenu
67 // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
69 $friend['id'] = $friend['cid'];
70 $photoMenu = Model\Contact::photoMenu($friend);
72 $connlnk = $app->getBaseURL() . '/follow/?url=' . $friend['url'];
74 'profile' => [L10n::t('View Profile'), Model\Contact::magicLinkbyId($friend['id'], $friend['url'])],
75 'follow' => [L10n::t('Connect/Follow'), $connlnk]
80 'url' => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
81 'itemurl' => defaults($contactDetails, 'addr', $friend['url']),
82 'name' => $contactDetails['name'],
83 'thumb' => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB),
84 'img_hover' => $contactDetails['name'],
85 'details' => $contactDetails['location'],
86 'tags' => $contactDetails['keywords'],
87 'about' => $contactDetails['about'],
88 'account_type' => Model\Contact::getAccountType($contactDetails),
89 'network' => ContactSelector::networkToName($contactDetails['network'], $contactDetails['url']),
90 'photoMenu' => $photoMenu,
91 'conntxt' => L10n::t('Connect'),
92 'connlnk' => $connlnk,
98 $tab_str = Contact::getTabsHTML($app, $contact, 4);
100 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
101 return Renderer::replaceMacros($tpl, [
102 '$tab_str' => $tab_str,
103 '$contacts' => $entries,
104 '$paginate' => $pager->renderFull($total),