From d234304580f506266aef8e3c893c4de8493ba879 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 29 Dec 2014 11:22:22 +0100 Subject: Add files for the new favicon system Use https://github.com/ArthurHoaro/favicon See https://github.com/FreshRSS/FreshRSS/issues/290 --- lib/Favicon/DataAccess.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/Favicon/DataAccess.php (limited to 'lib/Favicon/DataAccess.php') diff --git a/lib/Favicon/DataAccess.php b/lib/Favicon/DataAccess.php new file mode 100644 index 000000000..2bfdf640e --- /dev/null +++ b/lib/Favicon/DataAccess.php @@ -0,0 +1,40 @@ +set_context(); + return @file_get_contents($url); + } + + public function retrieveHeader($url) { + $this->set_context(); + return @get_headers($url, TRUE); + } + + public function saveCache($file, $data) { + file_put_contents($file, $data); + } + + public function readCache($file) { + return file_get_contents($file); + } + + private function set_context() { + stream_context_set_default( + array( + 'http' => array( + 'method' => 'GET', + '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", + ) + ) + ); + } +} \ No newline at end of file -- cgit v1.2.3 From f3696784ea0acd15a11a4ca193abe623fd77dc33 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 23 Apr 2016 21:35:09 +0200 Subject: Favicon array bug Case problem and isset check --- lib/Favicon/DataAccess.php | 3 ++- lib/Favicon/Favicon.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/Favicon/DataAccess.php') diff --git a/lib/Favicon/DataAccess.php b/lib/Favicon/DataAccess.php index 2bfdf640e..17f26b333 100644 --- a/lib/Favicon/DataAccess.php +++ b/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) { diff --git a/lib/Favicon/Favicon.php b/lib/Favicon/Favicon.php index 7ea6ccf16..1912050d6 100644 --- a/lib/Favicon/Favicon.php +++ b/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; -- cgit v1.2.3 From b5ffa8cb479131f68139ec40313fa22a3c08240d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 7 Oct 2016 19:50:59 +0200 Subject: Auto-refresh favicons Every 15 days. https://github.com/FreshRSS/FreshRSS/issues/1181 --- lib/Favicon/DataAccess.php | 2 +- p/f.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/Favicon/DataAccess.php') diff --git a/lib/Favicon/DataAccess.php b/lib/Favicon/DataAccess.php index 17f26b333..ae7509881 100644 --- a/lib/Favicon/DataAccess.php +++ b/lib/Favicon/DataAccess.php @@ -16,7 +16,7 @@ class DataAccess { public function retrieveHeader($url) { $this->set_context(); $headers = @get_headers($url, 1); - return array_change_key_case($headers); + return $headers ? array_change_key_case($headers) : array(); } public function saveCache($file, $data) { diff --git a/p/f.php b/p/f.php index 0f23921e3..6523cc759 100644 --- a/p/f.php +++ b/p/f.php @@ -15,6 +15,7 @@ $default_favicon = PUBLIC_PATH . '/themes/icons/default_favicon.ico'; function download_favicon($website, $dest) { global $favicons_dir, $default_favicon; + syslog(LOG_DEBUG, 'FreshRSS Favicon discovery GET ' . $website); $favicon_getter = new \Favicon\Favicon(); $favicon_getter->setCacheDir($favicons_dir); $favicon_url = $favicon_getter->get($website); @@ -23,6 +24,7 @@ function download_favicon($website, $dest) { return @copy($default_favicon, $dest); } + syslog(LOG_DEBUG, 'FreshRSS Favicon GET ' . $favicon_url); $c = curl_init($favicon_url); curl_setopt($c, CURLOPT_HEADER, false); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); @@ -69,18 +71,22 @@ $txt_mtime = @filemtime($txt); header('Content-Type: image/x-icon'); -if ($ico_mtime == false || $txt_mtime > $ico_mtime) { +if ($ico_mtime == false || $txt_mtime > $ico_mtime || ($ico_mtime < time() - 15 * 86400)) { if ($txt_mtime == false) { show_default_favicon(1800); - return; + exit(); } // no ico file or we should download a new one. $url = file_get_contents($txt); if (!download_favicon($url, $ico)) { - // Download failed, show the default favicon - show_default_favicon(86400); - return; + // Download failed + if ($ico_mtime == false) { + show_default_favicon(86400); + exit(); + } else { + touch($ico); + } } } -- cgit v1.2.3