]> git.mxchange.org Git - friendica.git/blob - src/Module/AllFriends.php
Remove deprecated App::getBaseURL() - process methods to DI::baseUrl()->get()
[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\DI;
11 use Friendica\Model;
12 use Friendica\Network\HTTPException;
13 use Friendica\Util\Proxy as ProxyUtils;
14
15 /**
16  * This module shows all public friends of the selected contact
17  */
18 class AllFriends extends BaseModule
19 {
20         public static function content(array $parameters = [])
21         {
22                 $app = DI::app();
23
24                 if (!local_user()) {
25                         throw new HTTPException\ForbiddenException();
26                 }
27
28                 $cid = 0;
29
30                 // @TODO: Replace with parameter from router
31                 if ($app->argc > 1) {
32                         $cid = intval($app->argv[1]);
33                 }
34
35                 if (!$cid) {
36                         throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
37                 }
38
39                 $uid = $app->user['uid'];
40
41                 $contact = Model\Contact::getContactForUser($cid, local_user(), ['name', 'url', 'photo', 'uid', 'id']);
42
43                 if (empty($contact)) {
44                         throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
45                 }
46
47                 $app->page['aside'] = "";
48                 Model\Profile::load($app, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
49
50                 $total = Model\GContact::countAllFriends(local_user(), $cid);
51
52                 $pager = new Pager($app->query_string);
53
54                 $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
55                 if (empty($friends)) {
56                         return L10n::t('No friends to display.');
57                 }
58
59                 $id = 0;
60
61                 $entries = [];
62                 foreach ($friends as $friend) {
63                         //get further details of the contact
64                         $contactDetails = Model\Contact::getDetailsByURL($friend['url'], $uid, $friend);
65
66                         $connlnk = '';
67                         // $friend[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photoMenu
68                         // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
69                         if ($friend['cid']) {
70                                 $friend['id'] = $friend['cid'];
71                                 $photoMenu = Model\Contact::photoMenu($friend);
72                         } else {
73                                 $connlnk = DI::baseUrl()->get() . '/follow/?url=' . $friend['url'];
74                                 $photoMenu = [
75                                         'profile' => [L10n::t('View Profile'), Model\Contact::magicLinkbyId($friend['id'], $friend['url'])],
76                                         'follow'  => [L10n::t('Connect/Follow'), $connlnk]
77                                 ];
78                         }
79
80                         $entry = [
81                                 'url'          => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
82                                 'itemurl'      => ($contactDetails['addr'] ?? '') ?: $friend['url'],
83                                 'name'         => $contactDetails['name'],
84                                 'thumb'        => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB),
85                                 'img_hover'    => $contactDetails['name'],
86                                 'details'      => $contactDetails['location'],
87                                 'tags'         => $contactDetails['keywords'],
88                                 'about'        => $contactDetails['about'],
89                                 'account_type' => Model\Contact::getAccountType($contactDetails),
90                                 'network'      => ContactSelector::networkToName($contactDetails['network'], $contactDetails['url']),
91                                 'photoMenu'    => $photoMenu,
92                                 'conntxt'      => L10n::t('Connect'),
93                                 'connlnk'      => $connlnk,
94                                 'id'           => ++$id,
95                         ];
96                         $entries[] = $entry;
97                 }
98
99                 $tab_str = Contact::getTabsHTML($app, $contact, 4);
100
101                 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
102                 return Renderer::replaceMacros($tpl, [
103                         '$tab_str'  => $tab_str,
104                         '$contacts' => $entries,
105                         '$paginate' => $pager->renderFull($total),
106                 ]);
107         }
108 }