Ejemplo n.º 1
0
 /**
  * Look up and if necessary create an Ostatus_profile for the remote entity
  * with the given profile page URL. This should never return null -- you
  * will either get an object or an exception will be thrown.
  *
  * @param string $profile_url
  * @return Ostatus_profile
  * @throws Exception on various error conditions
  * @throws OStatusShadowException if this reference would obscure a local user/group
  */
 public static function ensureProfileURL($profile_url, $hints = array())
 {
     $oprofile = self::getFromProfileURL($profile_url);
     if (!empty($oprofile)) {
         return $oprofile;
     }
     $hints['profileurl'] = $profile_url;
     // Fetch the URL
     // XXX: HTTP caching
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($profile_url);
     if (!$response->isOk()) {
         // TRANS: Exception. %s is a profile URL.
         throw new Exception(sprintf(_m('Could not reach profile page %s.'), $profile_url));
     }
     // Check if we have a non-canonical URL
     $finalUrl = $response->getUrl();
     if ($finalUrl != $profile_url) {
         $hints['profileurl'] = $finalUrl;
         $oprofile = self::getFromProfileURL($finalUrl);
         if (!empty($oprofile)) {
             return $oprofile;
         }
     }
     // Try to get some hCard data
     $body = $response->getBody();
     $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
     if (!empty($hcardHints)) {
         $hints = array_merge($hints, $hcardHints);
     }
     // Check if they've got an LRDD header
     $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
     if (!empty($lrdd)) {
         $xrd = Discovery::fetchXrd($lrdd);
         $xrdHints = DiscoveryHints::fromXRD($xrd);
         $hints = array_merge($hints, $xrdHints);
     }
     // If discovery found a feedurl (probably from LRDD), use it.
     if (array_key_exists('feedurl', $hints)) {
         return self::ensureFeedURL($hints['feedurl'], $hints);
     }
     // Get the feed URL from HTML
     $discover = new FeedDiscovery();
     $feedurl = $discover->discoverFromHTML($finalUrl, $body);
     if (!empty($feedurl)) {
         $hints['feedurl'] = $feedurl;
         return self::ensureFeedURL($feedurl, $hints);
     }
     // TRANS: Exception. %s is a URL.
     throw new Exception(sprintf(_m('Could not find a feed URL for profile page %s.'), $finalUrl));
 }
Ejemplo n.º 2
0
 public function discover($uri)
 {
     if (Discovery::isWebfinger($uri)) {
         // We have a webfinger acct: - start with host-meta
         list($name, $domain) = explode('@', $uri);
     } else {
         $domain = parse_url($uri, PHP_URL_HOST);
     }
     $url = 'http://' . $domain . '/.well-known/host-meta';
     $xrd = Discovery::fetchXrd($url);
     if ($xrd) {
         if ($xrd->host != $domain) {
             return false;
         }
         return $xrd->links;
     }
 }