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