From 4abcc53a178b8393ecbe812567093d89e1827eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20T=C3=A4tzner?= Date: Mon, 23 Jul 2012 21:02:49 +0200 Subject: Use base url for extracting favicon --- lib/utils.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/utils.php b/lib/utils.php index 2afa229ca..3e7562609 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -43,23 +43,22 @@ class OC_News_Utils { $feed = new OC_News_Feed($url, $title, $items); $favicon = $spfeed->get_image_url(); - //check if this file exists and the size with getimagesize() - if ($favicon == null) { //try really hard to find a favicon - if( null !== ($webFavicon = OC_News_Utils::discoverFavicon($url)) ) - $feed->setFavicon($webFavicon); - } - else { //use favicon from feed + if ($favicon !== null) { // use favicon from feed if(OC_News_Utils::checkFavicon($favicon)) $feed->setFavicon($favicon); } + else { // try really hard to find a favicon + if( null !== ($webFavicon = OC_News_Utils::discoverFavicon($url)) ) + $feed->setFavicon($webFavicon); + } return $feed; } public static function checkFavicon($favicon) { $file = new SimplePie_File($favicon); - //TODO additional checks? + //TODO additional checks? getimagesize()? if($file->success && strlen($file->body) > 0) { $sniffer = new SimplePie_Content_Type_Sniffer($file); if(substr($sniffer->get_type(), 0, 6) === 'image/') { @@ -77,8 +76,10 @@ class OC_News_Utils { return $favicon; //try to extract favicon from web page + $absoluteUrl = SimplePie_Misc::absolutize_url('/', $url); + $handle = curl_init ( ); - curl_setopt ( $handle, CURLOPT_URL, $url ); + curl_setopt ( $handle, CURLOPT_URL, $absoluteUrl ); curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $handle, CURLOPT_FOLLOWLOCATION, TRUE ); curl_setopt ( $handle, CURLOPT_MAXREDIRS, 10 ); -- cgit v1.2.3