function connectWebfinger($acct) { $target_profile = $this->targetProfile(); $disco = new Discovery(); $xrd = $disco->lookup($acct); $link = $xrd->get('http://ostatus.org/schema/1.0/tag'); if (!is_null($link)) { // We found a URL - let's redirect! if (!empty($link->template)) { $url = Discovery::applyTemplate($link->template, $target_profile); } else { $url = $link->href; } common_log(LOG_INFO, "Sending remote subscriber {$acct} to {$url}"); common_redirect($url, 303); } // TRANS: Client error displayed when remote profile address could not be confirmed. $this->clientError(_m('Could not confirm remote profile address.')); }
function connectWebfinger($acct) { $target_profile = $this->targetProfile(); $disco = new Discovery(); $result = $disco->lookup($acct); if (!$result) { // TRANS: Client error displayed when remote profile could not be looked up. $this->clientError(_m('Could not look up OStatus account profile.')); } foreach ($result->links as $link) { if ($link['rel'] == 'http://ostatus.org/schema/1.0/tag') { // We found a URL - let's redirect! $url = Discovery::applyTemplate($link['template'], $target_profile); common_log(LOG_INFO, "Sending remote subscriber {$acct} to {$url}"); common_redirect($url, 303); } } // TRANS: Client error displayed when remote profile address could not be confirmed. $this->clientError(_m('Could not confirm remote profile address.')); }
/** * This implements the actual lookup procedure */ public function lookup($id) { // Normalize the incoming $id to make sure we have a uri $uri = $this->normalize($id); 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 (!empty($link['template'])) { $xrd_uri = Discovery::applyTemplate($link['template'], $uri); } else { $xrd_uri = $link['href']; } $xrd = $this->fetchXrd($xrd_uri); if ($xrd) { return $xrd; } } } throw new Exception('Unable to find services for ' . $id); }
/** * Given a user ID, return the first available resource descriptor * * @param string $id User ID URI * * @return XML_XRD object for the resource descriptor of the id */ public function lookup($id) { // Normalize the incoming $id to make sure we have a uri $uri = self::normalize($id); foreach ($this->methods as $class) { try { $xrd = new XML_XRD(); common_debug("LRDD discovery method for '{$uri}': {$class}"); $lrdd = new $class(); $links = call_user_func(array($lrdd, 'discover'), $uri); $link = Discovery::getService($links, Discovery::LRDD_REL); // Load the LRDD XRD if (!empty($link->template)) { $xrd_uri = Discovery::applyTemplate($link->template, $uri); } elseif (!empty($link->href)) { $xrd_uri = $link->href; } else { throw new Exception('No resource descriptor URI in link.'); } $client = new HTTPClient(); $headers = array(); if (!is_null($link->type)) { $headers[] = "Accept: {$link->type}"; } $response = $client->get($xrd_uri, $headers); if ($response->getStatus() != 200) { throw new Exception('Unexpected HTTP status code.'); } $xrd->loadString($response->getBody()); return $xrd; } catch (Exception $e) { continue; } } // TRANS: Exception. %s is an ID. throw new Exception(sprintf(_('Unable to find services for %s.'), $id)); }