7 use Friendica\Core\Addon;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Database\DBM;
11 use Friendica\Protocol\Salmon;
13 function xrd_init(App $a)
15 if ($a->argv[0] == 'xrd') {
16 $uri = urldecode(notags(trim($_GET['uri'])));
17 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
23 $uri = urldecode(notags(trim($_GET['resource'])));
24 if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
31 if (substr($uri, 0, 4) === 'http') {
32 $name = ltrim(basename($uri), '~');
34 $local = str_replace('acct:', '', $uri);
35 if (substr($local, 0, 2) == '//') {
36 $local = substr($local, 2);
39 $name = substr($local, 0, strpos($local, '@'));
42 $user = DBA::selectFirst('user', [], ['nickname' => $name]);
43 if (!DBM::is_result($user)) {
47 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
49 $alias = str_replace('/profile/', '/~', $profile_url);
51 $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
53 $addr .= '/'.$a->get_path();
57 xrd_xml($a, $addr, $alias, $profile_url, $user);
59 xrd_json($a, $addr, $alias, $profile_url, $user);
63 function xrd_json($a, $uri, $alias, $profile_url, $r)
65 $salmon_key = Salmon::salmonKey($r['spubkey']);
67 header('Access-Control-Allow-Origin: *');
68 header("Content-type: application/json; charset=utf-8");
70 $json = ['subject' => $uri,
71 'aliases' => [$alias, $profile_url],
73 ['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
74 ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
75 ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
76 ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
77 ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
78 ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
79 ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
80 ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
81 ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
82 ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
83 ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
84 ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key],
85 ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-dfrn+json', 'href' => System::baseUrl().'/owa']
88 echo json_encode($json);
92 function xrd_xml($a, $uri, $alias, $profile_url, $r)
94 $salmon_key = Salmon::salmonKey($r['spubkey']);
96 header('Access-Control-Allow-Origin: *');
97 header("Content-type: text/xml");
99 $tpl = get_markup_template('xrd_person.tpl');
101 $o = replace_macros($tpl, [
102 '$nick' => $r['nickname'],
105 '$profile_url' => $profile_url,
106 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
107 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
108 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
109 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
110 '$baseurl' => System::baseUrl(),
111 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
112 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
113 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
114 '$openwebauth' => System::baseUrl() . '/owa',
115 '$modexp' => 'data:application/magic-public-key,' . $salmon_key]
118 $arr = ['user' => $r, 'xml' => $o];
119 Addon::callHooks('personal_xrd', $arr);