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