/** * Method wich tries to request an jrd document from the given url. Used * also in the webfinger class therefore it is here static * * @return PSX\Hostmeta\Document */ public static function requestJrd(Http $http, Url $url) { $request = new GetRequest($url, array('Accept' => 'application/jrd+json', 'User-Agent' => __CLASS__ . ' ' . Base::VERSION)); $request->setFollowLocation(true); $response = $http->request($request); if ($response->getStatusCode() == 200) { $contentType = $response->getHeader('Content-Type'); if (strpos($contentType, 'application/jrd+json') !== false || strpos($contentType, 'application/json') !== false) { $jrd = new Jrd(); $jrd->import(Json::decode($response->getBody())); return $jrd; } else { if (strpos($contentType, 'application/xrd+xml') !== false || strpos($contentType, 'application/xml') !== false) { $xrd = new Xrd(); $xrd->import(simplexml_load_string((string) $response->getBody())); return $xrd; } else { throw new Exception('Received unknown content type'); } } } else { throw new Exception('Invalid response code ' . $response->getStatusCode() . ' from ' . strval($url)); } }
/** * Discovers an openid identity (URI or XRI). It uses the xri.net web * service to resolve XRIs. Returns either an PSX\OpenId\Identity * * @param string $identity * @return PSX\OpenId\Identity */ private function discovery($identity) { $identity = $this->normalizeUri($identity); // we could get the identity via XRI if ($identity instanceof Identity) { return $identity; } else { if ($identity instanceof Url) { // YADIS discovery $discoveredIdentity = $this->fetchXrds($identity); // HTML based discovery if ($discoveredIdentity === false) { $request = new GetRequest($identity, array('User-Agent' => __CLASS__ . ' ' . Base::VERSION)); $request->setFollowLocation(true); $response = $this->http->request($request); return $this->htmlBasedDiscovery((string) $response->getBody()); } else { return $discoveredIdentity; } } else { throw new Exception('Invalid openid identity'); } } }
public function request(Url $url) { $request = new GetRequest($url, array('Accept' => 'application/xrds+xml', 'User-Agent' => __CLASS__ . ' ' . Base::VERSION)); $request->setFollowLocation(true); $response = $this->http->request($request); return $response; }
/** * $url should be an url to an ATOM or RSS feed. If the feed has an hub tag * the url will be returned as PSX\Url object * * @param PSX\Url $url * @return PSX\Url|boolean */ public function discover(Url $url, $type = 0) { $reader = new Xml(); $request = new GetRequest($url); $request->setFollowLocation(true); $response = $this->http->request($request); switch ($type) { case self::RSS2: $dom = $reader->read($response); $elements = $dom->getElementsByTagNameNS(Atom::$xmlns, 'link'); break; case self::ATOM: default: $dom = $reader->read($response); $elements = $dom->getElementsByTagName('link'); break; } for ($i = 0; $i < $elements->length; $i++) { $link = $elements->item($i); if (strcasecmp($link->getAttribute('rel'), 'hub') == 0) { $href = new Url($link->getAttribute('href')); return $this->lastHub = $href; } } return false; }