]> git.mxchange.org Git - friendica.git/blob - mod/allfriends.php
Merge pull request #4195 from zeroadam/ContactSelector-#3878
[friendica.git] / mod / allfriends.php
1 <?php
2
3 /**
4  * @file mod/allfriends.php
5  */
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Contact;
11 use Friendica\Model\GContact;
12
13 require_once 'mod/contacts.php';
14
15 function allfriends_content(App $a)
16 {
17         $o = '';
18         if (!local_user()) {
19                 notice(t('Permission denied.') . EOL);
20                 return;
21         }
22
23         $cid = 0;
24         if ($a->argc > 1) {
25                 $cid = intval($a->argv[1]);
26         }
27
28         if (!$cid) {
29                 return;
30         }
31
32         $uid = $a->user['uid'];
33
34         $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
35                 intval($cid),
36                 intval(local_user())
37         );
38
39         if (!DBM::is_result($c)) {
40                 return;
41         }
42
43         $a->page['aside'] = "";
44         profile_load($a, "", 0, Contact::getDetailsByURL($c[0]["url"]));
45
46         $total = GContact::countAllFriends(local_user(), $cid);
47
48         $a->set_pager_total($total);
49
50         $r = GContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
51         if (!DBM::is_result($r)) {
52                 $o .= 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 = 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 = Contact::photoMenu($rr);
71                 } else {
72                         $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
73                         $photo_menu = array(
74                                 'profile' => array(t("View Profile"), zrl($rr['url'])),
75                                 'follow' => array(t("Connect/Follow"), $connlnk)
76                         );
77                 }
78
79                 $entry = array(
80                         'url'          => $rr['url'],
81                         'itemurl'      => defaults($contact_details, 'addr', $rr['url']),
82                         'name'         => htmlentities($contact_details['name']),
83                         'thumb'        => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
84                         'img_hover'    => htmlentities($contact_details['name']),
85                         'details'      => $contact_details['location'],
86                         'tags'         => $contact_details['keywords'],
87                         'about'        => $contact_details['about'],
88                         'account_type' => Contact::getAccountType($contact_details),
89                         'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
90                         'photo_menu'   => $photo_menu,
91                         'conntxt'      => t('Connect'),
92                         'connlnk'      => $connlnk,
93                         'id'           => ++$id,
94                 );
95                 $entries[] = $entry;
96         }
97
98         $tab_str = contacts_tab($a, $cid, 3);
99
100         $tpl = get_markup_template('viewcontact_template.tpl');
101
102         $o .= replace_macros($tpl, array(
103                 //'$title' => sprintf( t('Friends of %s'), htmlentities($c[0]['name'])),
104                 '$tab_str' => $tab_str,
105                 '$contacts' => $entries,
106                 '$paginate' => paginate($a),
107         ));
108
109         return $o;
110 }