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