]> git.mxchange.org Git - friendica.git/blob - mod/allfriends.php
Rewrite Proxy module
[friendica.git] / mod / allfriends.php
1 <?php
2 /**
3  * @file mod/allfriends.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Pager;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Model;
14 use Friendica\Module;
15 use Friendica\Util\Proxy as ProxyUtils;
16
17
18 function allfriends_content(App $a)
19 {
20         $o = '';
21         if (!local_user()) {
22                 notice(L10n::t('Permission denied.') . EOL);
23                 return;
24         }
25
26         $cid = 0;
27         if ($a->argc > 1) {
28                 $cid = intval($a->argv[1]);
29         }
30
31         if (!$cid) {
32                 return;
33         }
34
35         $uid = $a->user['uid'];
36
37         $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => local_user()]);
38
39         if (!DBA::isResult($contact)) {
40                 return;
41         }
42
43         $a->page['aside'] = "";
44         Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
45
46         $total = Model\GContact::countAllFriends(local_user(), $cid);
47
48         $pager = new Pager($a->query_string);
49
50         $r = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
51         if (!DBA::isResult($r)) {
52                 $o .= L10n::t('No friends to display.');
53                 return $o;
54         }
55
56         $id = 0;
57
58         $entries = [];
59         foreach ($r as $rr) {
60                 //get further details of the contact
61                 $contact_details = Model\Contact::getDetailsByURL($rr['url'], $uid, $rr);
62
63                 $photo_menu = '';
64
65                 $connlnk = '';
66                 // $rr[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photo_menu
67                 // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
68                 if ($rr['cid']) {
69                         $rr['id'] = $rr['cid'];
70                         $photo_menu = Model\Contact::photoMenu($rr);
71                 } else {
72                         $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
73                         $photo_menu = [
74                                 'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($rr['url'])],
75                                 'follow' => [L10n::t("Connect/Follow"), $connlnk]
76                         ];
77                 }
78
79                 $entry = [
80                         'url'          => Model\Contact::magicLink($rr['url']),
81                         'itemurl'      => defaults($contact_details, 'addr', $rr['url']),
82                         'name'         => $contact_details['name'],
83                         'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
84                         'img_hover'    => $contact_details['name'],
85                         'details'      => $contact_details['location'],
86                         'tags'         => $contact_details['keywords'],
87                         'about'        => $contact_details['about'],
88                         'account_type' => Model\Contact::getAccountType($contact_details),
89                         'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
90                         'photo_menu'   => $photo_menu,
91                         'conntxt'      => L10n::t('Connect'),
92                         'connlnk'      => $connlnk,
93                         'id'           => ++$id,
94                 ];
95                 $entries[] = $entry;
96         }
97
98         $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
99
100         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
101         $o .= Renderer::replaceMacros($tpl, [
102                 '$tab_str' => $tab_str,
103                 '$contacts' => $entries,
104                 '$paginate' => $pager->renderFull($total),
105         ]);
106
107         return $o;
108 }