Răsfoiți Sursa

Merge branch 'favicon_bug' into dev

Alexandre Alapetite 10 ani în urmă
părinte
comite
be4f588911
3 a modificat fișierele cu 8 adăugiri și 8 ștergeri
  1. 2 1
      lib/Favicon/DataAccess.php
  2. 1 1
      lib/Favicon/Favicon.php
  3. 5 6
      p/f.php

+ 2 - 1
lib/Favicon/DataAccess.php

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

+ 1 - 1
lib/Favicon/Favicon.php

@@ -99,7 +99,7 @@ class Favicon
             switch ($status) {
                 case '301':
                 case '302':
-                    $url = $headers['Location'];
+                    $url = isset($headers['location']) ? $headers['location'] : '';
                     break;
                 default:
                     $loop = FALSE;

+ 5 - 6
p/f.php

@@ -44,14 +44,13 @@ function download_favicon($website, $dest) {
 }
 
 
-function show_default_favicon() {
+function show_default_favicon($cacheSeconds = 3600) {
 	global $default_favicon;
 
-	header('Content-Type: image/x-icon');
 	header('Content-Disposition: inline; filename="default_favicon.ico"');
 
 	$default_mtime = @filemtime($default_favicon);
-	if (!httpConditional($default_mtime, 2592000, 2)) {
+	if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
 		readfile($default_favicon);
 	}
 }
@@ -68,10 +67,11 @@ $ico = $favicons_dir . $id . '.ico';
 $ico_mtime = @filemtime($ico);
 $txt_mtime = @filemtime($txt);
 
+header('Content-Type: image/x-icon');
 
 if ($ico_mtime == false || $txt_mtime > $ico_mtime) {
 	if ($txt_mtime == false) {
-		show_default_favicon();
+		show_default_favicon(1800);
 		return;
 	}
 
@@ -79,12 +79,11 @@ if ($ico_mtime == false || $txt_mtime > $ico_mtime) {
 	$url = file_get_contents($txt);
 	if (!download_favicon($url, $ico)) {
 		// Download failed, show the default favicon
-		show_default_favicon();
+		show_default_favicon(86400);
 		return;
 	}
 }
 
-header('Content-Type: image/x-icon');
 header('Content-Disposition: inline; filename="' . $id . '.ico"');
 
 if (!httpConditional($ico_mtime, 2592000, 2)) {