]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Hovercard.php
Merge pull request #7828 from nupplaphil/task/move_enotify
[friendica.git] / src / Module / Contact / Hovercard.php
1 <?php
2
3 namespace Friendica\Module\Contact;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\Config;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Model\GContact;
12 use Friendica\Network\HTTPException;
13 use Friendica\Util\Strings;
14 use Friendica\Util\Proxy;
15
16 /**
17  * Asynchronous HTML fragment provider for frio contact hovercards
18  */
19 class Hovercard extends BaseModule
20 {
21         public static function rawContent(array $parameters = [])
22         {
23                 $contact_url = $_REQUEST['url'] ?? '';
24
25                 // Get out if the system doesn't have public access allowed
26                 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
27                         throw new HTTPException\ForbiddenException();
28                 }
29
30                 // If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
31                 // the contact. So we strip out the contact id from the internal url and look in the contact table for
32                 // the real url (nurl)
33                 if (strpos($contact_url, 'redir/') === 0) {
34                         $cid = intval(substr($contact_url, 6));
35                         $remote_contact = Contact::selectFirst(['nurl'], ['id' => $cid]);
36                         $contact_url = $remote_contact['nurl'] ?? '';
37                 }
38
39                 $contact = [];
40
41                 // if it's the url containing https it should be converted to http
42                 $contact_nurl = Strings::normaliseLink(GContact::cleanContactUrl($contact_url));
43                 if (!$contact_nurl) {
44                         throw new HTTPException\BadRequestException();
45                 }
46
47                 // Search for contact data
48                 // Look if the local user has got the contact
49                 if (Session::isAuthenticated()) {
50                         $contact = Contact::getDetailsByURL($contact_nurl, local_user());
51                 }
52
53                 // If not then check the global user
54                 if (!count($contact)) {
55                         $contact = Contact::getDetailsByURL($contact_nurl);
56                 }
57
58                 // Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url
59                 if (!count($contact) && Session::isAuthenticated()) {
60                         $contact_nurl = Strings::normaliseLink($contact_url);
61                         $contact = Contact::getDetailsByURL($contact_nurl, local_user());
62                 }
63
64                 if (!count($contact)) {
65                         $contact_nurl = Strings::normaliseLink($contact_url);
66                         $contact = Contact::getDetailsByURL($contact_nurl);
67                 }
68
69                 if (!count($contact)) {
70                         throw new HTTPException\NotFoundException();
71                 }
72
73                 // Get the photo_menu - the menu if possible contact actions
74                 if (Session::isAuthenticated()) {
75                         $actions = Contact::photoMenu($contact);
76                 } else {
77                         $actions = [];
78                 }
79
80                 // Move the contact data to the profile array so we can deliver it to
81                 $tpl = Renderer::getMarkupTemplate('hovercard.tpl');
82                 $o = Renderer::replaceMacros($tpl, [
83                         '$profile' => [
84                                 'name'         => $contact['name'],
85                                 'nick'         => $contact['nick'],
86                                 'addr'         => $contact['addr'] ?: $contact['url'],
87                                 'thumb'        => Proxy::proxifyUrl($contact['thumb'], false, Proxy::SIZE_THUMB),
88                                 'url'          => Contact::magicLink($contact['url']),
89                                 'nurl'         => $contact['nurl'],
90                                 'location'     => $contact['location'],
91                                 'gender'       => $contact['gender'],
92                                 'about'        => $contact['about'],
93                                 'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
94                                 'tags'         => $contact['keywords'],
95                                 'bd'           => $contact['birthday'] <= DBA::NULL_DATE ? '' : $contact['birthday'],
96                                 'account_type' => Contact::getAccountType($contact),
97                                 'actions'      => $actions,
98                         ],
99                 ]);
100
101                 echo $o;
102                 exit();
103         }
104 }