]> git.mxchange.org Git - friendica.git/blob - mod/allfriends.php
Merge pull request #4035 from friendica/revert-4031-task/3878-move-objects-to-model
[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 use Friendica\Object\Contact;
10
11 require_once 'include/contact_selectors.php';
12 require_once 'mod/contacts.php';
13
14 function allfriends_content(App $a) {
15
16         $o = '';
17         if (! local_user()) {
18                 notice( t('Permission denied.') . EOL);
19                 return;
20         }
21
22         if ($a->argc > 1) {
23                 $cid = intval($a->argv[1]);
24         }
25
26         if (! $cid) {
27                 return;
28         }
29
30         $uid = $a->user['uid'];
31
32         $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
33                 intval($cid),
34                 intval(local_user())
35         );
36
37         if (! DBM::is_result($c)) {
38                 return;
39         }
40
41         $a->page['aside'] = "";
42         profile_load($a, "", 0, Contact::getDetailsByURL($c[0]["url"]));
43
44         $total = GlobalContact::countAllFriends(local_user(), $cid);
45
46         if(count($total))
47                 $a->set_pager_total($total);
48
49         $r = GlobalContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
50
51         if (! DBM::is_result($r)) {
52                 $o .= t('No friends to display.');
53                 return $o;
54         }
55
56         $id = 0;
57
58         foreach ($r as $rr) {
59
60                 //get further details of the contact
61                 $contact_details = Contact::getDetailsByURL($rr['url'], $uid, $rr);
62
63                 $photo_menu = '';
64
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                 }
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'      => (($contact_details['addr'] != "") ? $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'      => network_to_name($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 }