]> git.mxchange.org Git - friendica.git/blob - src/Module/HoverCard.php
0ca74c514e1f0b4ad5c52447eca8e9389b22bf77
[friendica.git] / src / Module / HoverCard.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\App\Arguments;
6 use Friendica\App\BaseURL;
7 use Friendica\App\Page;
8 use Friendica\BaseModule;
9 use Friendica\Core\Config\Configuration;
10 use Friendica\Core\L10n\L10n;
11 use Friendica\Core\Session;
12 use Friendica\Model\Profile;
13 use Friendica\Model\User;
14 use Friendica\Network\HTTPException\NotFoundException;
15
16 /**
17  * Loads a profile for the HoverCard view
18  */
19 class HoverCard extends BaseModule
20 {
21         public static function rawContent(array $parameters = [])
22         {
23                 /** @var Arguments $args */
24                 $args = self::getClass(Arguments::class);
25
26                 $a = self::getApp();
27
28                 // A logged in user views a profile of a user
29                 if ((local_user()) && $args->get(2) === 'view') {
30                         $nickname = $a->user['nickname'];
31                         $profile  = $parameters['profile'];
32
33                         // Show the profile hovercard
34                 } elseif ($args->getArgc() < 2) {
35                         $nickname = $parameters['profile'];
36                         $profile  = 0;
37
38                 } else {
39                         /** @var L10n $l10n */
40                         $l10n = self::getClass(L10n::class);
41                         throw new NotFoundException($l10n->t('No profile'));
42                 }
43
44                 Profile::load($a, $nickname, $profile);
45
46                 /** @var Page $page */
47                 $page = self::getClass(Page::class);
48
49                 if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
50                         $page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
51                 }
52                 if (!empty($a->profile['openidserver'])) {
53                         $page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
54                 }
55                 if (!empty($a->profile['openid'])) {
56                         $delegate         = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
57                         $page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
58                 }
59
60                 /** @var Configuration $config */
61                 $config = self::getClass(Configuration::class);
62                 // check if blocked
63                 if ($config->get('system', 'block_public') && !Session::isAuthenticated()) {
64                         $keywords = $a->profile['pub_keywords'] ?? '';
65                         $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
66                         if (strlen($keywords)) {
67                                 $page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
68                         }
69                 }
70
71                 /** @var BaseURL $baseUrl */
72                 $baseUrl = self::getClass(BaseURL::class);
73
74                 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
75
76                 $page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n";
77                 $page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl->get() . '/dfrn_poll/' . $nickname . '" />' . "\r\n";
78                 $page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl->get() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
79                 header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
80
81                 foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
82                         $page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
83                 }
84         }
85 }