6 use Friendica\Core\Addon;
7 use Friendica\Core\System;
8 use Friendica\Database\DBM;
9 use Friendica\Protocol\Salmon;
11 function xrd_init(App $a)
13 if ($a->argv[0] == 'xrd') {
14 $uri = urldecode(notags(trim($_GET['uri'])));
15 if ($_SERVER['HTTP_ACCEPT'] == 'application/jrd+json') {
21 $uri = urldecode(notags(trim($_GET['resource'])));
22 if ($_SERVER['HTTP_ACCEPT'] == 'application/xrd+xml') {
29 if (substr($uri, 0, 4) === 'http') {
30 $name = ltrim(basename($uri), '~');
32 $local = str_replace('acct:', '', $uri);
33 if (substr($local, 0, 2) == '//') {
34 $local = substr($local, 2);
37 $name = substr($local, 0, strpos($local, '@'));
40 $user = dba::selectFirst('user', [], ['nickname' => $name]);
41 if (!DBM::is_result($user)) {
45 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
47 $alias = str_replace('/profile/', '/~', $profile_url);
49 $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
51 $addr .= '/'.$a->get_path();
55 xrd_xml($a, $addr, $alias, $profile_url, $user);
57 xrd_json($a, $addr, $alias, $profile_url, $user);
61 function xrd_json($a, $uri, $alias, $profile_url, $r)
63 $salmon_key = Salmon::salmonKey($r['spubkey']);
65 header('Access-Control-Allow-Origin: *');
66 header("Content-type: application/json; charset=utf-8");
68 $json = ['subject' => $uri,
69 'aliases' => [$alias, $profile_url],
70 'links' => [['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
71 ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
72 ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
73 ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
74 ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
75 ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
76 ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
77 ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
78 ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
79 ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
80 ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
81 ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key]
83 echo json_encode($json);
87 function xrd_xml($a, $uri, $alias, $profile_url, $r)
89 $salmon_key = Salmon::salmonKey($r['spubkey']);
91 header('Access-Control-Allow-Origin: *');
92 header("Content-type: text/xml");
94 $tpl = get_markup_template('xrd_person.tpl');
96 $o = replace_macros($tpl, [
97 '$nick' => $r['nickname'],
100 '$profile_url' => $profile_url,
101 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
102 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
103 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
104 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
105 '$baseurl' => System::baseUrl(),
106 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
107 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
108 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
109 '$modexp' => 'data:application/magic-public-key,' . $salmon_key]
112 $arr = ['user' => $r, 'xml' => $o];
113 Addon::callHooks('personal_xrd', $arr);