From: Michael Date: Fri, 23 Jul 2021 12:38:29 +0000 (+0000) Subject: "hovercard" is "hcard" X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9a3a4def3dcd40fad9946037441e55586b3dd815;p=friendica.git "hovercard" is "hcard" --- diff --git a/src/Module/HCard.php b/src/Module/HCard.php new file mode 100644 index 0000000000..e348f2ff5b --- /dev/null +++ b/src/Module/HCard.php @@ -0,0 +1,92 @@ +. + * + */ + +namespace Friendica\Module; + +use Friendica\BaseModule; +use Friendica\Core\Session; +use Friendica\DI; +use Friendica\Model\Profile; +use Friendica\Model\User; +use Friendica\Network\HTTPException; + +/** + * Loads a profile for the hCard page + * @see http://microformats.org/wiki/hcard + */ +class HCard extends BaseModule +{ + public static function rawContent(array $parameters = []) + { + $a = DI::app(); + + if ((local_user()) && ($parameters['action'] ?? '') === 'view') { + // A logged in user views a profile of a user + $nickname = $a->user['nickname']; + } elseif (empty($parameters['action'])) { + // Show the profile hCard + $nickname = $parameters['profile']; + } else { + throw new HTTPException\NotFoundException(DI::l10n()->t('No profile')); + } + + Profile::load($a, $nickname); + + if (empty($a->profile)) { + throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); + } + + $page = DI::page(); + + if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) { + $page['htmlhead'] .= ''; + } + if (!empty($a->profile['openidserver'])) { + $page['htmlhead'] .= '' . "\r\n"; + } + if (!empty($a->profile['openid'])) { + $delegate = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']); + $page['htmlhead'] .= '' . "\r\n"; + } + + // check if blocked + if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + $keywords = $a->profile['pub_keywords'] ?? ''; + $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords); + if (strlen($keywords)) { + $page['htmlhead'] .= '' . "\r\n"; + } + } + + $baseUrl = DI::baseUrl(); + + $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : '')); + + $page['htmlhead'] .= '' . "\r\n"; + $page['htmlhead'] .= '' . "\r\n"; + $page['htmlhead'] .= '' . "\r\n"; + header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); + + foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) { + $page['htmlhead'] .= "get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n"; + } + } +} diff --git a/src/Module/HoverCard.php b/src/Module/HoverCard.php deleted file mode 100644 index f86bb95973..0000000000 --- a/src/Module/HoverCard.php +++ /dev/null @@ -1,91 +0,0 @@ -. - * - */ - -namespace Friendica\Module; - -use Friendica\BaseModule; -use Friendica\Core\Session; -use Friendica\DI; -use Friendica\Model\Profile; -use Friendica\Model\User; -use Friendica\Network\HTTPException; - -/** - * Loads a profile for the HoverCard view - */ -class HoverCard extends BaseModule -{ - public static function rawContent(array $parameters = []) - { - $a = DI::app(); - - if ((local_user()) && ($parameters['action'] ?? '') === 'view') { - // A logged in user views a profile of a user - $nickname = $a->user['nickname']; - } elseif (empty($parameters['action'])) { - // Show the profile hovercard - $nickname = $parameters['profile']; - } else { - throw new HTTPException\NotFoundException(DI::l10n()->t('No profile')); - } - - Profile::load($a, $nickname); - - if (empty($a->profile)) { - throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); - } - - $page = DI::page(); - - if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) { - $page['htmlhead'] .= ''; - } - if (!empty($a->profile['openidserver'])) { - $page['htmlhead'] .= '' . "\r\n"; - } - if (!empty($a->profile['openid'])) { - $delegate = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']); - $page['htmlhead'] .= '' . "\r\n"; - } - - // check if blocked - if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { - $keywords = $a->profile['pub_keywords'] ?? ''; - $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords); - if (strlen($keywords)) { - $page['htmlhead'] .= '' . "\r\n"; - } - } - - $baseUrl = DI::baseUrl(); - - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : '')); - - $page['htmlhead'] .= '' . "\r\n"; - $page['htmlhead'] .= '' . "\r\n"; - $page['htmlhead'] .= '' . "\r\n"; - header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); - - foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) { - $page['htmlhead'] .= "get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n"; - } - } -} diff --git a/static/routes.config.php b/static/routes.config.php index b4b9c6a535..9780bf3cbe 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -292,7 +292,7 @@ return [ '/hashtag' => [Module\Hashtag::class, [R::GET]], '/help[/{doc:.+}]' => [Module\Help::class, [R::GET]], '/home' => [Module\Home::class, [R::GET]], - '/hcard/{profile}[/{action}]' => [Module\HoverCard::class, [R::GET]], + '/hcard/{profile}[/{action}]' => [Module\HCard::class, [R::GET]], '/inbox[/{nickname}]' => [Module\ActivityPub\Inbox::class, [R::GET, R::POST]], '/invite' => [Module\Invite::class, [R::GET, R::POST]],