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