]> git.mxchange.org Git - friendica.git/blob - src/Module/HoverCard.php
Merge pull request #8026 from nupplaphil/task/l10n_immutable
[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                 $a = self::getApp();
24
25                 if ((local_user()) && ($parameters['action'] ?? '') === 'view') {
26                         // A logged in user views a profile of a user
27                         $nickname = $a->user['nickname'];
28                         $profile  = $parameters['profile'];
29                 } elseif (empty($parameters['action'])) {
30                         // Show the profile hovercard
31                         $nickname = $parameters['profile'];
32                         $profile  = 0;
33                 } else {
34                         /** @var L10n $l10n */
35                         $l10n = self::getClass(L10n::class);
36                         throw new NotFoundException($l10n->t('No profile'));
37                 }
38
39                 Profile::load($a, $nickname, $profile);
40
41                 /** @var Page $page */
42                 $page = self::getClass(Page::class);
43
44                 if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
45                         $page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
46                 }
47                 if (!empty($a->profile['openidserver'])) {
48                         $page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
49                 }
50                 if (!empty($a->profile['openid'])) {
51                         $delegate         = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
52                         $page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
53                 }
54
55                 /** @var Configuration $config */
56                 $config = self::getClass(Configuration::class);
57                 // check if blocked
58                 if ($config->get('system', 'block_public') && !Session::isAuthenticated()) {
59                         $keywords = $a->profile['pub_keywords'] ?? '';
60                         $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
61                         if (strlen($keywords)) {
62                                 $page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
63                         }
64                 }
65
66                 /** @var BaseURL $baseUrl */
67                 $baseUrl = self::getClass(BaseURL::class);
68
69                 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
70
71                 $page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n";
72                 $page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl->get() . '/dfrn_poll/' . $nickname . '" />' . "\r\n";
73                 $page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl->get() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
74                 header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
75
76                 foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
77                         $page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
78                 }
79         }
80 }