]> git.mxchange.org Git - friendica.git/blob - src/Module/HCard.php
Use rawContent for Special Options to avoid a protected options() method
[friendica.git] / src / Module / HCard.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;
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 hCard page
33  * @see http://microformats.org/wiki/hcard
34  */
35 class HCard extends BaseModule
36 {
37         protected function content(array $request = []): string
38         {
39                 if ((local_user()) && ($this->parameters['action'] ?? '') === 'view') {
40                         // A logged in user views a profile of a user
41                         $nickname = DI::app()->getLoggedInUserNickname();
42                 } elseif (empty($this->parameters['action'])) {
43                         // Show the profile hCard
44                         $nickname = $this->parameters['profile'];
45                 } else {
46                         throw new HTTPException\NotFoundException(DI::l10n()->t('No profile'));
47                 }
48
49                 $profile = User::getOwnerDataByNick($nickname);
50
51                 if (empty($profile)) {
52                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
53                 }
54
55                 $page = DI::page();
56
57                 if (!empty($profile['page-flags']) && ($profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
58                         $page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
59                 }
60                 if (!empty($profile['openidserver'])) {
61                         $page['htmlhead'] .= '<link rel="openid.server" href="' . $profile['openidserver'] . '" />' . "\r\n";
62                 }
63                 if (!empty($profile['openid'])) {
64                         $delegate         = ((strstr($profile['openid'], '://')) ? $profile['openid'] : 'http://' . $profile['openid']);
65                         $page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
66                 }
67
68                 $baseUrl = DI::baseUrl();
69
70                 $uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
71
72                 $page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($profile['net-publish'] ? 'true' : 'false') . '" />' . "\r\n";
73                 $page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl->get() . '/dfrn_poll/' . $nickname . '" />' . "\r\n";
74                 $page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl->get() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
75                 header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
76
77                 foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
78                         $page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
79                 }
80
81                 $block = (DI::config()->get('system', 'block_public') && !Session::isAuthenticated());
82
83                 // check if blocked
84                 if ($block) {
85                         $keywords = $profile['pub_keywords'] ?? '';
86                         $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
87                         if (strlen($keywords)) {
88                                 $page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
89                         }
90                 }
91
92                 $page['aside'] = Profile::getVCardHtml($profile, $block, false);
93
94                 return '';
95         }
96 }