diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 08:23:57 -0700 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-04 08:23:57 -0700 |
commit | 2d8b635796ba117619063792b0a00c50dc91d2a6 (patch) | |
tree | 2d731bf847b1f270bcdde8412706f565a0b883a5 | |
parent | 1ffedced057ad7968629c974574b5f66adf01b48 (diff) | |
parent | 42685490dfd7b9deaf54ed337aec92f251ef5adc (diff) |
Merge pull request #40 from jerrykan/favicon
Improve feedfetcher discoverFavicon()
-rw-r--r-- | utility/feedfetcher.php | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index 284c40ba7..5d600c5c6 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -159,16 +159,23 @@ class FeedFetcher implements IFeedFetcher { $page = $this->api->getUrlContent($absoluteUrl); if ( FALSE !== $page ) { - // FIXME: dont use regex to get xml, use xpath! - preg_match ( '/<[^>]*link[^>]*(rel=["\']icon["\']|rel=["\']shortcut icon["\']) .*href=["\']([^>]*)["\'].*>/iU', $page, $match ); - if (1<sizeof($match)) { - // the specified uri might be an url, an absolute or a relative path - // we have to turn it into an url to be able to display it out of context - $favicon = htmlspecialchars_decode ( $match[2] ); - // test for an url - if (parse_url($favicon,PHP_URL_SCHEME)) { - if($this->checkFavicon($favicon)) - return $favicon; + $doc = @\DOMDocument::loadHTML($page); + + if ( $doc !== FALSE ) { + $xpath = new \DOMXpath($doc); + $elements = $xpath->query("//link[contains(@rel, 'icon')]"); + + if ( $elements->length > 0 ) { + if ( $favicon = $elements->item(0)->getAttribute('href') ) { + // the specified uri might be an url, an absolute or a relative path + // we have to turn it into a url to be able to display it out of context + if ( !parse_url($favicon, PHP_URL_SCHEME) ) { + $favicon = \SimplePie_Misc::absolutize_url($favicon, $absoluteUrl); + } + + if($this->checkFavicon($favicon)) + return $favicon; + } } } } |