3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Hook;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\System;
9 use Friendica\Model\User;
10 use Friendica\Protocol\Salmon;
11 use Friendica\Util\Strings;
14 * Prints responses to /.well-known/webfinger or /xrd requests
16 class Xrd extends BaseModule
18 public static function rawContent()
20 $app = self::getApp();
22 // @TODO: Replace with parameter from router
23 if ($app->argv[0] == 'xrd') {
24 if (empty($_GET['uri'])) {
28 $uri = urldecode(Strings::escapeTags(trim($_GET['uri'])));
29 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
35 if (empty($_GET['resource'])) {
39 $uri = urldecode(Strings::escapeTags(trim($_GET['resource'])));
40 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
47 if (substr($uri, 0, 4) === 'http') {
48 $name = ltrim(basename($uri), '~');
50 $local = str_replace('acct:', '', $uri);
51 if (substr($local, 0, 2) == '//') {
52 $local = substr($local, 2);
55 $name = substr($local, 0, strpos($local, '@'));
58 $user = User::getByNickname($name);
61 throw new \Friendica\Network\HTTPException\NotFoundException();
64 $profileURL = $app->getBaseURL() . '/profile/' . $user['nickname'];
65 $alias = str_replace('/profile/', '/~', $profileURL);
67 $addr = 'acct:' . $user['nickname'] . '@' . $app->getHostName();
68 if ($app->getURLPath()) {
69 $addr .= '/' . $app->getURLPath();
73 self::printXML($addr, $alias, $profileURL, $app->getBaseURL(), $user);
75 self::printJSON($addr, $alias, $profileURL, $app->getBaseURL(), $user);
79 private static function printJSON($uri, $alias, $orofileURL, $baseURL, $user)
81 $salmon_key = Salmon::salmonKey($user['spubkey']);
83 header('Access-Control-Allow-Origin: *');
84 header('Content-type: application/json; charset=utf-8');
94 'rel' => NAMESPACE_DFRN,
95 'href' => $orofileURL,
98 'rel' => NAMESPACE_FEED,
99 'type' => 'application/atom+xml',
100 'href' => $baseURL . '/dfrn_poll/' . $user['nickname'],
103 'rel' => 'http://webfinger.net/rel/profile-page',
104 'type' => 'text/html',
105 'href' => $orofileURL,
109 'type' => 'application/activity+json',
110 'href' => $orofileURL,
113 'rel' => 'http://microformats.org/profile/hcard',
114 'type' => 'text/html',
115 'href' => $baseURL . '/hcard/' . $user['nickname'],
118 'rel' => NAMESPACE_POCO,
119 'href' => $baseURL . '/poco/' . $user['nickname'],
122 'rel' => 'http://webfinger.net/rel/avatar',
123 'type' => 'image/jpeg',
124 'href' => $baseURL . '/photo/profile/' . $user['uid'] . '.jpg',
127 'rel' => 'http://joindiaspora.com/seed_location',
128 'type' => 'text/html',
133 'href' => $baseURL . '/salmon/' . $user['nickname'],
136 'rel' => 'http://salmon-protocol.org/ns/salmon-replies',
137 'href' => $baseURL . '/salmon/' . $user['nickname'],
140 'rel' => 'http://salmon-protocol.org/ns/salmon-mention',
141 'href' => $baseURL . '/salmon/' . $user['nickname'] . '/mention',
144 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
145 'template' => $baseURL . '/follow?url={uri}',
148 'rel' => 'magic-public-key',
149 'href' => 'data:application/magic-public-key,' . $salmon_key,
152 'rel' => 'http://purl.org/openwebauth/v1',
153 'type' => 'application/x-zot+json',
154 'href' => $baseURL . '/owa',
159 echo json_encode($json);
163 private static function printXML($uri, $alias, $profileURL, $baseURL, $user)
165 $salmon_key = Salmon::salmonKey($user['spubkey']);
167 header('Access-Control-Allow-Origin: *');
168 header('Content-type: text/xml');
170 $tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
172 $o = Renderer::replaceMacros($tpl, [
173 '$nick' => $user['nickname'],
176 '$profile_url' => $profileURL,
177 '$hcard_url' => $baseURL . '/hcard/' . $user['nickname'],
178 '$atom' => $baseURL . '/dfrn_poll/' . $user['nickname'],
179 '$poco_url' => $baseURL . '/poco/' . $user['nickname'],
180 '$photo' => $baseURL . '/photo/profile/' . $user['uid'] . '.jpg',
181 '$baseurl' => $baseURL,
182 '$salmon' => $baseURL . '/salmon/' . $user['nickname'],
183 '$salmen' => $baseURL . '/salmon/' . $user['nickname'] . '/mention',
184 '$subscribe' => $baseURL . '/follow?url={uri}',
185 '$openwebauth' => $baseURL . '/owa',
186 '$modexp' => 'data:application/magic-public-key,' . $salmon_key
189 $arr = ['user' => $user, 'xml' => $o];
190 Hook::callAll('personal_xrd', $arr);