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 if (empty($_GET['uri'])) {
19 $uri = urldecode(notags(trim($_GET['uri'])));
20 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
26 if (empty($_GET['resource'])) {
30 $uri = urldecode(notags(trim($_GET['resource'])));
31 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
38 if (substr($uri, 0, 4) === 'http') {
39 $name = ltrim(basename($uri), '~');
41 $local = str_replace('acct:', '', $uri);
42 if (substr($local, 0, 2) == '//') {
43 $local = substr($local, 2);
46 $name = substr($local, 0, strpos($local, '@'));
49 $user = DBA::selectFirst('user', [], ['nickname' => $name]);
50 if (!DBA::isResult($user)) {
54 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
56 $alias = str_replace('/profile/', '/~', $profile_url);
58 $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
60 $addr .= '/'.$a->get_path();
64 xrd_xml($a, $addr, $alias, $profile_url, $user);
66 xrd_json($a, $addr, $alias, $profile_url, $user);
70 function xrd_json($a, $uri, $alias, $profile_url, $r)
72 $salmon_key = Salmon::salmonKey($r['spubkey']);
74 header('Access-Control-Allow-Origin: *');
75 header("Content-type: application/json; charset=utf-8");
77 $json = ['subject' => $uri,
78 'aliases' => [$alias, $profile_url],
80 ['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
81 ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
82 ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
83 ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url],
84 ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
85 ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
86 ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
87 ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
88 ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
89 ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
90 ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
91 ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
92 ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key],
93 ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-dfrn+json', 'href' => System::baseUrl().'/owa']
97 echo json_encode($json);
101 function xrd_xml($a, $uri, $alias, $profile_url, $r)
103 $salmon_key = Salmon::salmonKey($r['spubkey']);
105 header('Access-Control-Allow-Origin: *');
106 header("Content-type: text/xml");
108 $tpl = get_markup_template('xrd_person.tpl');
110 $o = replace_macros($tpl, [
111 '$nick' => $r['nickname'],
114 '$profile_url' => $profile_url,
115 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
116 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
117 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
118 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
119 '$baseurl' => System::baseUrl(),
120 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
121 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
122 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
123 '$openwebauth' => System::baseUrl() . '/owa',
124 '$modexp' => 'data:application/magic-public-key,' . $salmon_key]
127 $arr = ['user' => $r, 'xml' => $o];
128 Addon::callHooks('personal_xrd', $arr);