Example #1
0
 public function discover(Url $url, $raw = false, $deep = 0)
 {
     if ($this->maxRecursion >= $deep) {
         $response = $this->request($url);
         $location = (string) $response->getHeader('X-XRDS-Location');
         // x-xrds-location
         if (!empty($location)) {
             $location = new Url($location);
             if (strcasecmp($url, $location) != 0) {
                 return $this->discover($location, $raw, $deep++);
             }
         }
         // application/xrds+xml
         // we check whether the content type contains the string "xml" i.e.
         // text/xml or application/xrds+xml ... after the specification we
         // only must check for the content-type application/xrds+xml but
         // some websites serve the xrds document as text/xml
         $contentType = (string) $response->getHeader('Content-Type');
         if (!empty($contentType) && strpos($contentType, 'xml') !== false) {
             if ($raw === true) {
                 return (string) $response->getBody();
             } else {
                 return $this->parse((string) $response->getBody());
             }
         }
         // search for <meta /> tag
         $parse = new Parse((string) $response->getBody());
         $element = new Element('meta', array('http-equiv' => 'X-XRDS-Location'));
         $location = $parse->fetchAttrFromHead($element, 'content');
         if (!empty($location)) {
             return $this->discover($location, $raw, $deep++);
         }
         // we dont find anything
         return false;
     } else {
         throw new Exception('Max recurison level reached');
     }
 }
Example #2
0
 private function htmlBasedDiscovery($html)
 {
     $parse = new Parse($html);
     $element = new Element('link', array('rel' => 'openid2.provider'));
     $server = $parse->fetchAttrFromHead($element, 'href');
     if (empty($server)) {
         $element->setAttributes(array('rel' => 'openid.server'));
         $server = $parse->fetchAttrFromHead($element, 'href');
     }
     $element = new Element('link', array('rel' => 'openid2.local_id'));
     $localId = $parse->fetchAttrFromHead($element, 'href');
     if (empty($localId)) {
         $element->setAttributes(array('rel' => 'openid.delegate'));
         $localId = $parse->fetchAttrFromHead($element, 'href');
     }
     if (!empty($server)) {
         $identity = new Identity($server, $localId);
         return $identity;
     } else {
         throw new Exception('Couldnt find server in identifier');
     }
 }
Example #3
0
 public static function findTag($content)
 {
     $parse = new Parse($content);
     $element = new Element('link', array('rel' => 'pingback'));
     $href = $parse->fetchAttrFromHead($element, 'href');
     if (empty($href)) {
         throw new Exception('Could not discover pingback link');
     }
     return $href;
 }
Example #4
0
 public static function findTag($content)
 {
     $parse = new Parse($content);
     $element = new Element('link', array('rel' => 'alternate', 'type' => 'application/json+oembed'));
     $href = $parse->fetchAttrFromHead($element, 'href');
     if (empty($href)) {
         $element = new Element('link', array('rel' => 'alternate', 'type' => 'text/xml+oembed'));
         $href = $parse->fetchAttrFromHead($element, 'href');
         if (empty($href)) {
             throw new Exception('Could not discover oembed link');
         }
     }
     return $href;
 }