]> git.mxchange.org Git - friendica.git/blob - mod/viewcontacts.php
The central item fetch does work now and the API now uses these functions
[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 function viewcontacts_content(App $a)
41 {
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         $is_owner = $a->profile['profile_uid'] == local_user();
50
51         $o = "";
52
53         // tabs
54         $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
55
56         if (((! count($a->profile)) || ($a->profile['hide-friends']))) {
57                 notice(L10n::t('Permission denied.') . EOL);
58                 return $o;
59         }
60
61         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
62                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
63                         AND NOT `hidden` AND NOT `archive`
64                         AND `network` IN ('%s', '%s', '%s')",
65                 intval($a->profile['uid']),
66                 dbesc(NETWORK_DFRN),
67                 dbesc(NETWORK_DIASPORA),
68                 dbesc(NETWORK_OSTATUS)
69         );
70         if (DBM::is_result($r)) {
71                 $a->set_pager_total($r[0]['total']);
72         }
73
74         $r = q("SELECT * FROM `contact`
75                 WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
76                         AND NOT `hidden` AND NOT `archive`
77                         AND `network` IN ('%s', '%s', '%s')
78                 ORDER BY `name` ASC LIMIT %d, %d",
79                 intval($a->profile['uid']),
80                 dbesc(NETWORK_DFRN),
81                 dbesc(NETWORK_DIASPORA),
82                 dbesc(NETWORK_OSTATUS),
83                 intval($a->pager['start']),
84                 intval($a->pager['itemspage'])
85         );
86         if (!DBM::is_result($r)) {
87                 info(L10n::t('No contacts.').EOL);
88                 return $o;
89         }
90
91         $contacts = [];
92
93         foreach ($r as $rr) {
94                 /// @TODO This triggers an E_NOTICE if 'self' is not there
95                 if ($rr['self']) {
96                         continue;
97                 }
98
99                 $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
100
101                 $contacts[] = [
102                         'id' => $rr['id'],
103                         'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
104                         'photo_menu' => Contact::photoMenu($rr),
105                         'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
106                         'name' => htmlentities(substr($contact_details['name'], 0, 20)),
107                         'username' => htmlentities($contact_details['name']),
108                         'details'       => $contact_details['location'],
109                         'tags'          => $contact_details['keywords'],
110                         'about'         => $contact_details['about'],
111                         'account_type'  => Contact::getAccountType($contact_details),
112                         'url' => Contact::magicLink($rr['url']),
113                         'sparkle' => '',
114                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
115                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
116                 ];
117         }
118
119
120         $tpl = get_markup_template("viewcontact_template.tpl");
121         $o .= replace_macros($tpl, [
122                 '$title' => L10n::t('Contacts'),
123                 '$contacts' => $contacts,
124                 '$paginate' => paginate($a),
125         ]);
126
127
128         return $o;
129 }