]> git.mxchange.org Git - friendica.git/blob - mod/allfriends.php
GlobalContact created
[friendica.git] / mod / allfriends.php
1 <?php
2 /**
3  * @file mod/allfriends.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\GlobalContact;
9
10 require_once 'include/socgraph.php';
11 require_once 'include/Contact.php';
12 require_once 'include/contact_selectors.php';
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         if ($a->argc > 1) {
24                 $cid = intval($a->argv[1]);
25         }
26
27         if (! $cid) {
28                 return;
29         }
30
31         $uid = $a->user['uid'];
32
33         $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
34                 intval($cid),
35                 intval(local_user())
36         );
37
38         if (! DBM::is_result($c)) {
39                 return;
40         }
41
42         $a->page['aside'] = "";
43         profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
44
45         $total = GlobalContact::countAllFriends(local_user(), $cid);
46
47         if(count($total))
48                 $a->set_pager_total($total);
49
50         $r = GlobalContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
51
52         if (! DBM::is_result($r)) {
53                 $o .= t('No friends to display.');
54                 return $o;
55         }
56
57         $id = 0;
58
59         foreach ($r as $rr) {
60
61                 //get further details of the contact
62                 $contact_details = get_contact_details_by_url($rr['url'], $uid, $rr);
63
64                 $photo_menu = '';
65
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_photo_menu ($rr);
71                 }
72                 else {
73                         $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
74                         $photo_menu = array(
75                                 'profile' => array(t("View Profile"), zrl($rr['url'])),
76                                 'follow' => array(t("Connect/Follow"), $connlnk)
77                         );
78                 }
79
80                 $entry = array(
81                         'url'          => $rr['url'],
82                         'itemurl'      => (($contact_details['addr'] != "") ? $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' => account_type($contact_details),
90                         'network'      => network_to_name($contact_details['network'], $contact_details['url']),
91                         'photo_menu'   => $photo_menu,
92                         'conntxt'      => 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,array(
104                 //'$title' => sprintf( 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 }