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