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