From b34c66d08d301df1585a15e2a4657a9a1cd11de7 Mon Sep 17 00:00:00 2001 From: Phyks Date: Fri, 18 Jul 2014 23:34:58 +0200 Subject: [PATCH] Only check HTML files with first method --- favicon.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/favicon.php b/favicon.php index e7f489e..8d38d81 100644 --- a/favicon.php +++ b/favicon.php @@ -32,7 +32,12 @@ function getFavicon($urls) { // Convert array to the good format for curl downloader $curl_urls = array(); foreach($urls as $url) { - $curl_urls[] = array('url'=>$url); + if (endswith($url, '.html')) { // Only check html files using first method + $curl_urls[] = array('url'=>$url); + } + else { + $errors[] = $url; + } } $contents = curl_downloader($curl_urls); @@ -97,7 +102,7 @@ function getFavicon($urls) { $parsed_url = parse_url(trim($url)); $second_try_url = ""; if(isset($parsed_url['scheme'])) { - $second_try_url .= $parsed_url['scheme']; + $second_try_url .= $parsed_url['scheme'].'://'; } if(isset($parsed_url['host'])) { $second_try_url .= $parsed_url['host']; @@ -206,3 +211,16 @@ function curl_downloader($urls, $fetch_content=true) { } +/** + * Check that $haystack ends with $needle. + */ +function endswith($haystack, $needle) { + $length = strlen($needle); + if ($length == 0) { + return true; + } + + return (substr($haystack, -$length) === $needle); +} + +