]> git.mxchange.org Git - friendica.git/blob - src/Module/HoverCard.php
Further unused tables to be dropped
[friendica.git] / src / Module / HoverCard.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Session;
26 use Friendica\DI;
27 use Friendica\Model\Profile;
28 use Friendica\Model\User;
29 use Friendica\Network\HTTPException;
30
31 /**
32  * Loads a profile for the HoverCard view
33  */
34 class HoverCard extends BaseModule
35 {
36         public static function rawContent(array $parameters = [])
37         {
38                 $a = DI::app();
39
40                 if ((local_user()) && ($parameters['action'] ?? '') === 'view') {
41                         // A logged in user views a profile of a user
42                         $nickname = $a->user['nickname'];
43                 } elseif (empty($parameters['action'])) {
44                         // Show the profile hovercard
45                         $nickname = $parameters['profile'];
46                 } else {
47                         throw new HTTPException\NotFoundException(DI::l10n()->t('No profile'));
48                 }
49
50                 Profile::load($a, $nickname);
51
52                 if (empty($a->profile)) {
53                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
54                 }
55
56                 $page = DI::page();
57
58                 if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
59                         $page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
60                 }
61                 if (!empty($a->profile['openidserver'])) {
62                         $page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
63                 }
64                 if (!empty($a->profile['openid'])) {
65                         $delegate         = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
66                         $page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
67                 }
68
69                 // check if blocked
70                 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
71                         $keywords = $a->profile['pub_keywords'] ?? '';
72                         $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
73                         if (strlen($keywords)) {
74                                 $page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
75                         }
76                 }
77
78                 $baseUrl = DI::baseUrl();
79
80                 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
81
82                 $page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\r\n";
83                 $page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl->get() . '/dfrn_poll/' . $nickname . '" />' . "\r\n";
84                 $page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl->get() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
85                 header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
86
87                 foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
88                         $page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
89                 }
90         }
91 }