From 1af1b3702e5336947d49f62b21c21b1ad9f9fba8 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 22 Apr 2017 18:56:00 +0200 Subject: Use new version 1.2 of Favicon library --- lib/favicons.php | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'lib/favicons.php') diff --git a/lib/favicons.php b/lib/favicons.php index d8c97964e..0e80aa145 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -1,43 +1,21 @@ setCacheDir($favicons_dir); - $favicon_url = $favicon_getter->get($website); - - if ($favicon_url === false) { - return @copy($default_favicon, $dest); - } - - syslog(LOG_INFO, 'FreshRSS Favicon GET ' . $favicon_url); - $c = curl_init($favicon_url); - curl_setopt($c, CURLOPT_HEADER, false); - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); - curl_setopt($c, CURLOPT_BINARYTRANSFER, true); - curl_setopt($c, CURLOPT_USERAGENT, 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')'); - $img_raw = curl_exec($c); - $status_code = curl_getinfo($c, CURLINFO_HTTP_CODE); - curl_close($c); - - if ($status_code === 200) { - $file = fopen($dest, 'w'); - if ($file !== false) { - fwrite($file, $img_raw); - fclose($file); - return true; - } - } else { - syslog(LOG_WARNING, 'FreshRSS Favicon GET ' . $favicon_url . ' error ' . $status_code); - } + $tmpPath = realpath(TMP_PATH) . '/'; + $favicon_getter->setCacheDir($tmpPath); + $favicon_path = $favicon_getter->get($website, \Favicon\FaviconDLType::DL_FILE_PATH); - return false; + return ($favicon_path != false && @rename($tmpPath . $favicon_path, $dest)) || + @copy($default_favicon, $dest); } -- cgit v1.2.3 From 57f1e9d6570e86f1bc679ed4897437ae4b14a2b5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 22 Apr 2017 23:36:41 +0200 Subject: Fix some bugs of Favicon 1.2 https://github.com/ArthurHoaro/favicon/pull/6 https://github.com/ArthurHoaro/favicon/pull/7 --- lib/Favicon/Favicon.php | 18 ++++++++++++++---- lib/favicons.php | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'lib/favicons.php') diff --git a/lib/Favicon/Favicon.php b/lib/Favicon/Favicon.php index 7e6c42d6e..39f45f139 100644 --- a/lib/Favicon/Favicon.php +++ b/lib/Favicon/Favicon.php @@ -188,7 +188,10 @@ class Favicon // See if it's specified in a link tag in domain url. if (!$favicon) { - $favicon = $this->getInPage($url); + $favicon = trim($this->getInPage($url)); + } + if (substr($favicon, 0, 2) === '//') { + $favicon = 'https:' . $favicon; } // Make sure the favicon is an absolute URL. @@ -264,9 +267,15 @@ class Favicon foreach ($links as $link) { if ($link->hasAttribute('rel') && strtolower($link->getAttribute('rel')) == 'shortcut icon') { return $link->getAttribute('href'); - } elseif ($link->hasAttribute('rel') && strtolower($link->getAttribute('rel')) == 'icon') { + } + } + foreach ($links as $link) { + if ($link->hasAttribute('rel') && strtolower($link->getAttribute('rel')) == 'icon') { return $link->getAttribute('href'); - } elseif ($link->hasAttribute('href') && strpos($link->getAttribute('href'), 'favicon') !== FALSE) { + } + } + foreach ($links as $link) { + if ($link->hasAttribute('href') && strpos($link->getAttribute('href'), 'favicon') !== FALSE) { return $link->getAttribute('href'); } } @@ -319,7 +328,8 @@ class Favicon $fInfo = finfo_open(FILEINFO_MIME_TYPE); $isImage = strpos(finfo_buffer($fInfo, $content), 'image') !== false; finfo_close($fInfo); - } catch (Exception $e) { + } catch (\Exception $e) { + error_log('Favicon checkImageMTypeContent error: ' . $e->getMessage()); } return $isImage; diff --git a/lib/favicons.php b/lib/favicons.php index 0e80aa145..93e570d27 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -12,10 +12,10 @@ function download_favicon($website, $dest) { syslog(LOG_INFO, 'FreshRSS Favicon discovery GET ' . $website); $favicon_getter = new \Favicon\Favicon(); - $tmpPath = realpath(TMP_PATH) . '/'; + $tmpPath = realpath(TMP_PATH); $favicon_getter->setCacheDir($tmpPath); $favicon_path = $favicon_getter->get($website, \Favicon\FaviconDLType::DL_FILE_PATH); - return ($favicon_path != false && @rename($tmpPath . $favicon_path, $dest)) || + return ($favicon_path != false && @rename($tmpPath . '/' . $favicon_path, $dest)) || @copy($default_favicon, $dest); } -- cgit v1.2.3 From f483a5e95bc78cfb42e6fd90436c9f1c60e0242b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 23 Apr 2017 01:59:09 +0200 Subject: Favicon fix redirects https://github.com/ArthurHoaro/favicon/pull/5/commits/92b42591591b4282261f21ed5ffa553f5e987a9d --- lib/Favicon/DataAccess.php | 2 ++ lib/Favicon/Favicon.php | 3 +++ lib/favicons.php | 1 + 3 files changed, 6 insertions(+) (limited to 'lib/favicons.php') diff --git a/lib/Favicon/DataAccess.php b/lib/Favicon/DataAccess.php index 838df66c3..1445e9343 100644 --- a/lib/Favicon/DataAccess.php +++ b/lib/Favicon/DataAccess.php @@ -32,6 +32,8 @@ class DataAccess { array( 'http' => array( 'method' => 'GET', + 'follow_location' => 0, + 'max_redirects' => 1, 'timeout' => 10, 'header' => "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:20.0; Favicon; +https://github.com/ArthurHoaro/favicon) Gecko/20100101 Firefox/32.0\r\n", ) diff --git a/lib/Favicon/Favicon.php b/lib/Favicon/Favicon.php index 39f45f139..c026d8a95 100644 --- a/lib/Favicon/Favicon.php +++ b/lib/Favicon/Favicon.php @@ -111,6 +111,9 @@ class Favicon case '301': case '302': $url = isset($headers['location']) ? $headers['location'] : ''; + if (is_array($url)) { + $url = end($url); + } break; default: $loop = FALSE; diff --git a/lib/favicons.php b/lib/favicons.php index 93e570d27..d8baba342 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -14,6 +14,7 @@ function download_favicon($website, $dest) { $favicon_getter = new \Favicon\Favicon(); $tmpPath = realpath(TMP_PATH); $favicon_getter->setCacheDir($tmpPath); + $favicon_getter->setCacheTimeout(-1); $favicon_path = $favicon_getter->get($website, \Favicon\FaviconDLType::DL_FILE_PATH); return ($favicon_path != false && @rename($tmpPath . '/' . $favicon_path, $dest)) || -- cgit v1.2.3