3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module;
24 use Friendica\BaseModule;
26 use Friendica\Model\Profile;
27 use Friendica\Model\User;
28 use Friendica\Network\HTTPException;
31 * Loads a profile for the hCard page
32 * @see http://microformats.org/wiki/hcard
34 class HCard extends BaseModule
36 protected function content(array $request = []): string
38 if (DI::userSession()->getLocalUserId() && ($this->parameters['action'] ?? '') === 'view') {
39 // A logged in user views a profile of a user
40 $nickname = DI::app()->getLoggedInUserNickname();
41 } elseif (empty($this->parameters['action'])) {
42 // Show the profile hCard
43 $nickname = $this->parameters['profile'];
45 throw new HTTPException\NotFoundException(DI::l10n()->t('No profile'));
48 $profile = User::getOwnerDataByNick($nickname);
50 if (empty($profile)) {
51 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
56 if (!empty($profile['page-flags']) && ($profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
57 $page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
59 if (!empty($profile['openidserver'])) {
60 $page['htmlhead'] .= '<link rel="openid.server" href="' . $profile['openidserver'] . '" />' . "\r\n";
62 if (!empty($profile['openid'])) {
63 $delegate = ((strstr($profile['openid'], '://')) ? $profile['openid'] : 'http://' . $profile['openid']);
64 $page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
67 $baseUrl = DI::baseUrl();
69 $uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
71 $page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($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);
76 foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
77 $page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
80 $block = (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated());
84 $keywords = $profile['pub_keywords'] ?? '';
85 $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
86 if (strlen($keywords)) {
87 $page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
91 $page['aside'] = Profile::getVCardHtml($profile, $block, false);