]> git.mxchange.org Git - friendica.git/blob - src/Module/AllFriends.php
e5fbe697128d576374fd6fed2d9b2e75da3ee3ab
[friendica.git] / src / Module / AllFriends.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Content\ContactSelector;
7 use Friendica\Content\Pager;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Model;
11 use Friendica\Network\HTTPException;
12 use Friendica\Util\Proxy as ProxyUtils;
13
14 /**
15  * This module shows all public friends of the selected contact
16  */
17 class AllFriends extends BaseModule
18 {
19         public static function content()
20         {
21                 $app = self::getApp();
22
23                 if (!local_user()) {
24                         throw new HTTPException\ForbiddenException();
25                 }
26
27                 $cid = 0;
28
29                 // @TODO: Replace with parameter from router
30                 if ($app->argc > 1) {
31                         $cid = intval($app->argv[1]);
32                 }
33
34                 if (!$cid) {
35                         throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
36                 }
37
38                 $uid = $app->user['uid'];
39
40                 $contact = Model\Contact::getContactForUser($cid, local_user(), ['name', 'url', 'photo', 'uid', 'id']);
41
42                 if (empty($contact)) {
43                         throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
44                 }
45
46                 $app->page['aside'] = "";
47                 Model\Profile::load($app, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
48
49                 $total = Model\GContact::countAllFriends(local_user(), $cid);
50
51                 $pager = new Pager($app->query_string);
52
53                 $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
54                 if (empty($friends)) {
55                         return L10n::t('No friends to display.');
56                 }
57
58                 $id = 0;
59
60                 $entries = [];
61                 foreach ($friends as $friend) {
62                         //get further details of the contact
63                         $contactDetails = Model\Contact::getDetailsByURL($friend['url'], $uid, $friend);
64
65                         $connlnk = '';
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
68                         if ($friend['cid']) {
69                                 $friend['id'] = $friend['cid'];
70                                 $photoMenu = Model\Contact::photoMenu($friend);
71                         } else {
72                                 $connlnk = $app->getBaseURL() . '/follow/?url=' . $friend['url'];
73                                 $photoMenu = [
74                                         'profile' => [L10n::t('View Profile'), Model\Contact::magicLinkbyId($friend['id'], $friend['url'])],
75                                         'follow'  => [L10n::t('Connect/Follow'), $connlnk]
76                                 ];
77                         }
78
79                         $entry = [
80                                 'url'          => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
81                                 'itemurl'      => ($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,
93                                 'id'           => ++$id,
94                         ];
95                         $entries[] = $entry;
96                 }
97
98                 $tab_str = Contact::getTabsHTML($app, $contact, 4);
99
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),
105                 ]);
106         }
107 }