7 use Friendica\Core\Hook;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Protocol\Salmon;
12 use Friendica\Util\Strings;
14 function xrd_init(App $a)
16 if ($a->argv[0] == 'xrd') {
17 if (empty($_GET['uri'])) {
18 System::httpExit(404);
21 $uri = urldecode(Strings::escapeTags(trim($_GET['uri'])));
22 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
28 if (empty($_GET['resource'])) {
29 System::httpExit(404);
32 $uri = urldecode(Strings::escapeTags(trim($_GET['resource'])));
33 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
40 if (substr($uri, 0, 4) === 'http') {
41 $name = ltrim(basename($uri), '~');
43 $local = str_replace('acct:', '', $uri);
44 if (substr($local, 0, 2) == '//') {
45 $local = substr($local, 2);
48 $name = substr($local, 0, strpos($local, '@'));
51 $user = DBA::selectFirst('user', [], ['nickname' => $name]);
52 if (!DBA::isResult($user)) {
53 System::httpExit(404);
56 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
58 $alias = str_replace('/profile/', '/~', $profile_url);
60 $addr = 'acct:'.$user['nickname'].'@'.$a->getHostName();
61 if ($a->getURLPath()) {
62 $addr .= '/'.$a->getURLPath();
66 xrd_xml($addr, $alias, $profile_url, $user);
68 xrd_json($addr, $alias, $profile_url, $user);
72 function xrd_json($uri, $alias, $profile_url, $r)
74 $salmon_key = Salmon::salmonKey($r['spubkey']);
76 header('Access-Control-Allow-Origin: *');
77 header("Content-type: application/json; charset=utf-8");
79 $json = ['subject' => $uri,
80 'aliases' => [$alias, $profile_url],
82 ['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
83 ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
84 ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
85 ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url],
86 ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
87 ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
88 ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
89 ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
90 ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
91 ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
92 ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
93 ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
94 ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key],
95 ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-zot+json', 'href' => System::baseUrl().'/owa']
99 echo json_encode($json);
103 function xrd_xml($uri, $alias, $profile_url, $r)
105 $salmon_key = Salmon::salmonKey($r['spubkey']);
107 header('Access-Control-Allow-Origin: *');
108 header("Content-type: text/xml");
110 $tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
112 $o = Renderer::replaceMacros($tpl, [
113 '$nick' => $r['nickname'],
116 '$profile_url' => $profile_url,
117 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
118 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
119 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
120 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
121 '$baseurl' => System::baseUrl(),
122 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
123 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
124 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
125 '$openwebauth' => System::baseUrl() . '/owa',
126 '$modexp' => 'data:application/magic-public-key,' . $salmon_key]
129 $arr = ['user' => $r, 'xml' => $o];
130 Hook::callAll('personal_xrd', $arr);