7 use Friendica\Core\Addon;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Protocol\Salmon;
12 function xrd_init(App $a)
14 if ($a->argv[0] == 'xrd') {
15 $uri = urldecode(notags(trim($_GET['uri'])));
16 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
22 $uri = urldecode(notags(trim($_GET['resource'])));
23 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
30 if (substr($uri, 0, 4) === 'http') {
31 $name = ltrim(basename($uri), '~');
33 $local = str_replace('acct:', '', $uri);
34 if (substr($local, 0, 2) == '//') {
35 $local = substr($local, 2);
38 $name = substr($local, 0, strpos($local, '@'));
41 $user = DBA::selectFirst('user', [], ['nickname' => $name]);
42 if (!DBA::isResult($user)) {
46 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
48 $alias = str_replace('/profile/', '/~', $profile_url);
50 $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
52 $addr .= '/'.$a->get_path();
56 xrd_xml($a, $addr, $alias, $profile_url, $user);
58 xrd_json($a, $addr, $alias, $profile_url, $user);
62 function xrd_json($a, $uri, $alias, $profile_url, $r)
64 $salmon_key = Salmon::salmonKey($r['spubkey']);
66 header('Access-Control-Allow-Origin: *');
67 header("Content-type: application/json; charset=utf-8");
69 $json = ['subject' => $uri,
70 'aliases' => [$alias, $profile_url],
72 ['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
73 ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
74 ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
75 ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
76 ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
77 ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
78 ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
79 ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
80 ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
81 ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
82 ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
83 ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key],
84 ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-dfrn+json', 'href' => System::baseUrl().'/owa']
87 echo json_encode($json);
91 function xrd_xml($a, $uri, $alias, $profile_url, $r)
93 $salmon_key = Salmon::salmonKey($r['spubkey']);
95 header('Access-Control-Allow-Origin: *');
96 header("Content-type: text/xml");
98 $tpl = get_markup_template('xrd_person.tpl');
100 $o = replace_macros($tpl, [
101 '$nick' => $r['nickname'],
104 '$profile_url' => $profile_url,
105 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
106 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
107 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
108 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
109 '$baseurl' => System::baseUrl(),
110 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
111 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
112 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
113 '$openwebauth' => System::baseUrl() . '/owa',
114 '$modexp' => 'data:application/magic-public-key,' . $salmon_key]
117 $arr = ['user' => $r, 'xml' => $o];
118 Addon::callHooks('personal_xrd', $arr);