]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Hovercard.php
Removed redundant maximagesize = INF statements
[friendica.git] / src / Module / Contact / Hovercard.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Contact;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\System;
27 use Friendica\Database\DBA;
28 use Friendica\DI;
29 use Friendica\Model\Contact;
30 use Friendica\Network\HTTPException;
31 use Friendica\Util\Strings;
32
33 /**
34  * Asynchronous HTML fragment provider for frio contact hovercards
35  */
36 class Hovercard extends BaseModule
37 {
38         protected function rawContent(array $request = [])
39         {
40                 $contact_url = $_REQUEST['url'] ?? '';
41
42                 // Get out if the system doesn't have public access allowed
43                 if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
44                         throw new HTTPException\ForbiddenException();
45                 }
46
47                 /* Possible formats for relative URLs that need to be converted to the absolute contact URL:
48                  * - contact/redir/123456
49                  * - contact/123456/conversations
50                  */
51                 if (strpos($contact_url, 'contact/') === 0 && preg_match('/(\d+)/', $contact_url, $matches)) {
52                         $remote_contact = Contact::selectFirst(['nurl'], ['id' => $matches[1]]);
53                         $contact_url = $remote_contact['nurl'] ?? '';
54                 }
55
56                 if (!$contact_url) {
57                         throw new HTTPException\BadRequestException();
58                 }
59
60                 // Search for contact data
61                 // Look if the local user has got the contact
62                 if (DI::userSession()->isAuthenticated()) {
63                         $contact = Contact::getByURLForUser($contact_url, DI::userSession()->getLocalUserId());
64                 } else {
65                         $contact = Contact::getByURL($contact_url, false);
66                 }
67
68                 if (!count($contact)) {
69                         throw new HTTPException\NotFoundException();
70                 }
71
72                 // Get the photo_menu - the menu if possible contact actions
73                 if (DI::userSession()->isAuthenticated()) {
74                         $actions = Contact::photoMenu($contact);
75                 } else {
76                         $actions = [];
77                 }
78
79                 // Move the contact data to the profile array so we can deliver it to
80                 $tpl = Renderer::getMarkupTemplate('hovercard.tpl');
81                 $o = Renderer::replaceMacros($tpl, [
82                         '$profile' => [
83                                 'name'         => $contact['name'],
84                                 'nick'         => $contact['nick'],
85                                 'addr'         => $contact['addr'] ?: $contact['url'],
86                                 'thumb'        => Contact::getThumb($contact),
87                                 'url'          => Contact::magicLinkByContact($contact),
88                                 'nurl'         => $contact['nurl'],
89                                 'location'     => $contact['location'],
90                                 'about'        => $contact['about'],
91                                 'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
92                                 'tags'         => $contact['keywords'],
93                                 'bd'           => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
94                                 'account_type' => Contact::getAccountType($contact['contact-type']),
95                                 'actions'      => $actions,
96                         ],
97                 ]);
98
99                 echo $o;
100                 System::exit();
101         }
102 }