summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-08-19 13:49:58 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-08-19 13:49:58 -0400
commit8bea9cf893f2f0c80e3cfbafca9f8113c640eb99 (patch)
tree59df9254fcf21e66002c1dac5becbe69ad33b20b /lib
parentb9b010a72119d8cfc9806ba0842d7fa9247fc94d (diff)
improves favicon detection
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.php19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/utils.php b/lib/utils.php
index cc4dac232..b3ff3db0c 100644
--- a/lib/utils.php
+++ b/lib/utils.php
@@ -82,14 +82,15 @@ class Utils {
$feed = new Feed($url, $title, $items);
$favicon = $spfeed->get_image_url();
-
- if ($favicon !== null) { // use favicon from feed
- if(self::checkFavicon($favicon))
- $feed->setFavicon($favicon);
+
+ if ($favicon !== null && self::checkFavicon($favicon)) { // use favicon from feed
+ $feed->setFavicon($favicon);
}
else { // try really hard to find a favicon
- if( null !== ($webFavicon = self::discoverFavicon($url)) )
+ $webFavicon = self::discoverFavicon($url);
+ if ($webFavicon !== null) {
$feed->setFavicon($webFavicon);
+ }
}
return $feed;
}
@@ -129,14 +130,18 @@ class Utils {
}
public static function checkFavicon($favicon) {
+ var_dump($favicon);
$file = new \SimplePie_File($favicon);
// size in bytes
$filesize = strlen($file->body);
- if($file->success && $filesize > 0 && $filesize < 50000) {
+ if($file->success && $filesize > 0 && $filesize < 50000) { //bigger files are not considered favicons
$sniffer = new \SimplePie_Content_Type_Sniffer($file);
if(substr($sniffer->get_type(), 0, 6) === 'image/') {
- return true;
+ $imgsize = getimagesize($favicon);
+ if ($imgsize['0'] <= 32 && $imgsize['1'] <= 32) { //bigger images are not considered favicons
+ return true;
+ }
}
}
return false;