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