return true;
}
+ /**
+ * Add a link header for LRDD Discovery
+ */
+ function onStartShowHTML($action)
+ {
+ if ($action instanceof ShowstreamAction) {
+ $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
+ $url = common_local_url('xrd');
+ $url.= '?uri='. $acct;
+
+ header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
+ }
+ }
+
/**
* Set up a PuSH hub link to our internal link for canonical timeline
* Atom feeds for users and groups.
$user = User::staticGet('nickname', $this->nickname);
$target_profile = common_local_url('userbyid', array('id' => $user->id));
- $url = $w->applyTemplate($link['template'], $target_profile);
+ $url = Discovery::applyTemplate($link['template'], $target_profile);
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
common_redirect($url, 303);
}
foreach ($this->methods as $class) {
$links = call_user_func(array($class, 'discover'), $uri);
-
if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
// Load the LRDD XRD
if ($link['template']) {
}
return XRD::parse($response->getBody());
- }
+ }
}
interface Discovery_LRDD
{
public function discover($uri)
{
- if (Discovery::isWebfinger($uri)) {
- // We have a webfinger acct: - start with host-meta
- list($name, $domain) = explode('@', $id);
- } else {
- $domain = @parse_url($uri, PHP_URL_HOST);
+ if (!Discovery::isWebfinger($uri)) {
+ return false;
}
+ // We have a webfinger acct: - start with host-meta
+ list($name, $domain) = explode('@', $uri);
$url = 'http://'. $domain .'/.well-known/host-meta';
$xrd = Discovery::fetchXrd($url);
{
try {
$client = new HTTPClient();
- $response = $client->get($url);
+ $response = $client->get($uri);
} catch (HTTP_Request2_Exception $e) {
return false;
}
-
+
if ($response->getStatus() != 200) {
return false;
}
$link_header = $response->getHeader('Link');
if (!$link_header) {
- return false;
+ // return false;
}
- return Discovery_LRDD_Link_Header::parseHeader($header);
+ return Discovery_LRDD_Link_Header::parseHeader($link_header);
}
protected static function parseHeader($header)
{
preg_match('/^<[^>]+>/', $header, $uri_reference);
- if (empty($uri_reference)) return;
+ //if (empty($uri_reference)) return;
+
+ $links = array();
$link_uri = trim($uri_reference[0], '<>');
$link_rel = array();
$header = substr($header, strlen($uri_reference[0]));
// parse link-params
- $params = explode($header, ';');
+ $params = explode(';', $header);
foreach ($params as $param) {
if (empty($param)) continue;
$link_type = trim($param_value);
}
}
-
- return array(
+
+ $links[] = array(
'href' => $link_uri,
'rel' => $link_rel,
'type' => $link_type);
+
+ return $links;
}
}
{
try {
$client = new HTTPClient();
- $response = $client->get($url);
+ $response = $client->get($uri);
} catch (HTTP_Request2_Exception $e) {
return false;
}
{
$disco = new Discovery();
- $links = $disco->lookup($signer_uri);
- if ($link = Discovery::getService($links, 'magic-public-key')) {
+ $xrd = $disco->lookup($signer_uri);
+ if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
list($type, $keypair) = explode(';', $link['href']);
return $keypair;
}
throw new Exception('Unable to locate signer public key');
- //return 'RSA.79_L2gq-TD72Nsb5yGS0r9stLLpJZF5AHXyxzWmQmlqKl276LEJEs8CppcerLcR90MbYQUwt-SX9slx40Yq3vA==.AQAB.AR-jo5KMfSISmDAT2iMs2_vNFgWRjl5rbJVvA0SpGIEWyPdCGxlPtCbTexp8-0ZEIe8a4SyjatBECH5hxgMTpw==';
}