Only check HTML files with first method

This commit is contained in:
Phyks 2014-07-18 23:34:58 +02:00
parent 635a5068c5
commit b34c66d08d

View File

@ -32,8 +32,13 @@ function getFavicon($urls) {
// Convert array to the good format for curl downloader // Convert array to the good format for curl downloader
$curl_urls = array(); $curl_urls = array();
foreach($urls as $url) { foreach($urls as $url) {
if (endswith($url, '.html')) { // Only check html files using first method
$curl_urls[] = array('url'=>$url); $curl_urls[] = array('url'=>$url);
} }
else {
$errors[] = $url;
}
}
$contents = curl_downloader($curl_urls); $contents = curl_downloader($curl_urls);
foreach($contents['status_codes'] as $url=>$status) { foreach($contents['status_codes'] as $url=>$status) {
@ -97,7 +102,7 @@ function getFavicon($urls) {
$parsed_url = parse_url(trim($url)); $parsed_url = parse_url(trim($url));
$second_try_url = ""; $second_try_url = "";
if(isset($parsed_url['scheme'])) { if(isset($parsed_url['scheme'])) {
$second_try_url .= $parsed_url['scheme']; $second_try_url .= $parsed_url['scheme'].'://';
} }
if(isset($parsed_url['host'])) { if(isset($parsed_url['host'])) {
$second_try_url .= $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);
}