]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
51104c478322c9b84ec10a501e12c56d484658ec
[friendica.git] / mod / viewcontacts.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5
6 require_once('include/Contact.php');
7 require_once('include/contact_selectors.php');
8
9 function viewcontacts_init(App $a) {
10
11         if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
12                 return;
13         }
14
15         nav_set_selected('home');
16
17         if($a->argc > 1) {
18                 $nick = $a->argv[1];
19                 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
20                         dbesc($nick)
21                 );
22
23                 if (! dbm::is_result($r)) {
24                         return;
25                 }
26
27                 $a->data['user'] = $r[0];
28                 $a->profile_uid = $r[0]['uid'];
29                 $is_owner = (local_user() && (local_user() == $a->profile_uid));
30
31                 profile_load($a,$a->argv[1]);
32         }
33 }
34
35
36 function viewcontacts_content(App $a) {
37         require_once("mod/proxy.php");
38
39         if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
40                 notice( t('Public access denied.') . EOL);
41                 return;
42         }
43
44         $o = "";
45
46         // tabs
47         $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
48
49         if(((! count($a->profile)) || ($a->profile['hide-friends']))) {
50                 notice( t('Permission denied.') . EOL);
51                 return $o;
52         }
53
54         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
55                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
56                         AND NOT `hidden` AND NOT `archive`
57                         AND `network` IN ('%s', '%s', '%s')",
58                 intval($a->profile['uid']),
59                 dbesc(NETWORK_DFRN),
60                 dbesc(NETWORK_DIASPORA),
61                 dbesc(NETWORK_OSTATUS)
62         );
63         if (dbm::is_result($r))
64                 $a->set_pager_total($r[0]['total']);
65
66         $r = q("SELECT * FROM `contact`
67                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
68                         AND NOT `hidden` AND NOT `archive`
69                         AND `network` IN ('%s', '%s', '%s')
70                 ORDER BY `name` ASC LIMIT %d, %d",
71                 intval($a->profile['uid']),
72                 dbesc(NETWORK_DFRN),
73                 dbesc(NETWORK_DIASPORA),
74                 dbesc(NETWORK_OSTATUS),
75                 intval($a->pager['start']),
76                 intval($a->pager['itemspage'])
77         );
78         if (!dbm::is_result($r)) {
79                 info(t('No contacts.').EOL);
80                 return $o;
81         }
82
83         $contacts = array();
84
85         foreach ($r as $rr) {
86                 /// @TODO This triggers an E_NOTICE if 'self' is not there
87                 if ($rr['self']) {
88                         continue;
89                 }
90
91                 $url = $rr['url'];
92
93                 // route DFRN profiles through the redirect
94
95                 $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false);
96
97                 if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel']))
98                         $url = 'redir/' . $rr['id'];
99                 else
100                         $url = zrl($url);
101
102                 $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid'], $rr);
103
104                 $contacts[] = array(
105                         'id' => $rr['id'],
106                         'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $contact_details['name'], $rr['url']),
107                         'photo_menu' => contact_photo_menu($rr),
108                         'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
109                         'name' => htmlentities(substr($contact_details['name'],0,20)),
110                         'username' => htmlentities($contact_details['name']),
111                         'details'       => $contact_details['location'],
112                         'tags'          => $contact_details['keywords'],
113                         'about'         => $contact_details['about'],
114                         'account_type'  => account_type($contact_details),
115                         'url' => $url,
116                         'sparkle' => '',
117                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
118                         'network' => network_to_name($rr['network'], $rr['url']),
119                 );
120         }
121
122
123         $tpl = get_markup_template("viewcontact_template.tpl");
124         $o .= replace_macros($tpl, array(
125                 '$title' => t('Contacts'),
126                 '$contacts' => $contacts,
127                 '$paginate' => paginate($a),
128         ));
129
130
131         return $o;
132 }