Просмотр исходного кода

Re-apply Favicon FreshRSS patches

Patches sent upstream https://github.com/ArthurHoaro/favicon/pull/5
Alexandre Alapetite 9 лет назад
Родитель
Сommit
9588112e50
2 измененных файлов с 14 добавлено и 6 удалено
  1. 2 1
      lib/Favicon/DataAccess.php
  2. 12 5
      lib/Favicon/Favicon.php

+ 2 - 1
lib/Favicon/DataAccess.php

@@ -15,7 +15,8 @@ class DataAccess {
 	
 	
 	public function retrieveHeader($url) {
 	public function retrieveHeader($url) {
 	    $this->set_context();
 	    $this->set_context();
-		return @get_headers($url, TRUE);
+		$headers = @get_headers($url, 1);
+		return is_array($headers) ? array_change_key_case($headers) : array();
 	}
 	}
 	
 	
     public function saveCache($file, $data) {
     public function saveCache($file, $data) {

+ 12 - 5
lib/Favicon/Favicon.php

@@ -97,6 +97,9 @@ class Favicon
         $loop = TRUE;
         $loop = TRUE;
         while ($loop && $max_loop-- > 0) {
         while ($loop && $max_loop-- > 0) {
             $headers = $this->dataAccess->retrieveHeader($url);
             $headers = $this->dataAccess->retrieveHeader($url);
+            if (empty($headers)) {
+                return false;
+            }
             $exploded = explode(' ', $headers[0]);
             $exploded = explode(' ', $headers[0]);
             
             
             if( !isset($exploded[1]) ) { 
             if( !isset($exploded[1]) ) { 
@@ -107,7 +110,7 @@ class Favicon
             switch ($status) {
             switch ($status) {
                 case '301':
                 case '301':
                 case '302':
                 case '302':
-                    $url = $headers['Location'];
+                    $url = isset($headers['location']) ? $headers['location'] : '';
                     break;
                     break;
                 default:
                 default:
                     $loop = FALSE;
                     $loop = FALSE;
@@ -196,7 +199,7 @@ class Favicon
         // Sometimes people lie, so check the status.
         // Sometimes people lie, so check the status.
         // And sometimes, it's not even an image. Sneaky bastards!
         // And sometimes, it's not even an image. Sneaky bastards!
         // If cacheDir isn't writable, that's not our problem
         // If cacheDir isn't writable, that's not our problem
-        if ($favicon && is_writable($this->cacheDir) && !$this->checkImageMType($favicon)) {
+        if ($favicon && is_writable($this->cacheDir) && extension_loaded('fileinfo') && !$this->checkImageMType($favicon)) {
             $favicon = false;
             $favicon = false;
         }
         }
 
 
@@ -311,9 +314,13 @@ class Favicon
     private function checkImageMTypeContent($content) {
     private function checkImageMTypeContent($content) {
         if(empty($content)) return false;
         if(empty($content)) return false;
 
 
-        $fInfo = finfo_open(FILEINFO_MIME_TYPE);
-        $isImage = strpos(finfo_buffer($fInfo, $content), 'image') !== false;
-        finfo_close($fInfo);
+        $isImage = true;
+        try {
+            $fInfo = finfo_open(FILEINFO_MIME_TYPE);
+            $isImage = strpos(finfo_buffer($fInfo, $content), 'image') !== false;
+            finfo_close($fInfo);
+        } catch (Exception $e) {
+        }
 
 
         return $isImage;
         return $isImage;
     }
     }