http = $http; } public function parse($body, $url, $opts=[]) { if(isset($opts['timeout'])) $this->http->set_timeout($opts['timeout']); if(isset($opts['max_redirects'])) $this->http->set_max_redirects($opts['max_redirects']); // Check if the URL matches a special parser if(Formats\Instagram::matches($url)) { return Formats\Instagram::parse($this->http, $body, $url, $opts); } if(Formats\GitHub::matches($url)) { return Formats\GitHub::parse($body, $url); } if(Formats\Twitter::matches($url)) { return Formats\Twitter::parse($body, $url); } if(Formats\Facebook::matches($url)) { return Formats\Facebook::parse($body, $url); } if(Formats\XKCD::matches($url)) { return Formats\XKCD::parse($body, $url); } if(Formats\Hackernews::matches($url)) { return Formats\Hackernews::parse($body, $url); } // Check if an mf2 JSON object was passed in if(is_array($body) && isset($body['items'][0]['type']) && isset($body['items'][0]['properties'])) { return Formats\Mf2::parse($body, $url, $this->http, $opts); } if(substr($body, 0, 5) == 'http, $opts); } } // No special parsers matched, parse for Microformats now return Formats\HTML::parse($this->http, $body, $url, $opts); } }