6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Protocol\Salmon;
10 function xrd_init(App $a)
12 if ($a->argv[0] == 'xrd') {
13 $uri = urldecode(notags(trim($_GET['uri'])));
14 if ($_SERVER['HTTP_ACCEPT'] == 'application/jrd+json') {
20 $uri = urldecode(notags(trim($_GET['resource'])));
21 if ($_SERVER['HTTP_ACCEPT'] == 'application/xrd+xml') {
28 if (substr($uri, 0, 4) === 'http') {
29 $name = ltrim(basename($uri), '~');
31 $local = str_replace('acct:', '', $uri);
32 if (substr($local, 0, 2) == '//') {
33 $local = substr($local, 2);
36 $name = substr($local, 0, strpos($local, '@'));
39 $user = dba::selectFirst('user', [], ['nickname' => $name]);
40 if (!DBM::is_result($user)) {
44 $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
46 $alias = str_replace('/profile/', '/~', $profile_url);
48 $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
50 $addr .= '/'.$a->get_path();
54 xrd_xml($a, $addr, $alias, $profile_url, $user);
56 xrd_json($a, $addr, $alias, $profile_url, $user);
60 function xrd_json($a, $uri, $alias, $profile_url, $r)
62 $salmon_key = Salmon::salmonKey($r['spubkey']);
64 header('Access-Control-Allow-Origin: *');
65 header("Content-type: application/json; charset=utf-8");
67 $json = array('subject' => $uri,
68 'aliases' => array($alias, $profile_url),
69 'links' => array(array('rel' => NAMESPACE_DFRN, 'href' => $profile_url),
70 array('rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']),
71 array('rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url),
72 array('rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']),
73 array('rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']),
74 array('rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'),
75 array('rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()),
76 array('rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']),
77 array('rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']),
78 array('rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'),
79 array('rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'),
80 array('rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key)
82 echo json_encode($json);
86 function xrd_xml($a, $uri, $alias, $profile_url, $r)
88 $salmon_key = Salmon::salmonKey($r['spubkey']);
90 header('Access-Control-Allow-Origin: *');
91 header("Content-type: text/xml");
93 $tpl = get_markup_template('xrd_person.tpl');
95 $o = replace_macros($tpl, array(
96 '$nick' => $r['nickname'],
99 '$profile_url' => $profile_url,
100 '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'],
101 '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'],
102 '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'],
103 '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg',
104 '$baseurl' => System::baseUrl(),
105 '$salmon' => System::baseUrl() . '/salmon/' . $r['nickname'],
106 '$salmen' => System::baseUrl() . '/salmon/' . $r['nickname'] . '/mention',
107 '$subscribe' => System::baseUrl() . '/follow?url={uri}',
108 '$modexp' => 'data:application/magic-public-key,' . $salmon_key)
111 $arr = array('user' => $r, 'xml' => $o);
112 call_hooks('personal_xrd', $arr);