diff options
| author | 2017-02-15 14:14:03 +0100 | |
|---|---|---|
| committer | 2017-02-15 14:14:03 +0100 | |
| commit | 5a1bb1393b4496eb35a2ffb3cc63d41c9dc1e2e5 (patch) | |
| tree | 67028e45792c575c25c92616633f64cc7a4a13eb /lib/favicons.php | |
| parent | 7e949d50320317b5c3b5a2da2bdaf324e794b2f7 (diff) | |
| parent | 5f637bd816b7323885bfe1751a1724ee59a822f6 (diff) | |
Merge remote-tracking branch 'FreshRSS/master'
Diffstat (limited to 'lib/favicons.php')
| -rw-r--r-- | lib/favicons.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/favicons.php b/lib/favicons.php new file mode 100644 index 000000000..d8c97964e --- /dev/null +++ b/lib/favicons.php @@ -0,0 +1,43 @@ +<?php + +include(LIB_PATH . '/Favicon/Favicon.php'); +include(LIB_PATH . '/Favicon/DataAccess.php'); + +$favicons_dir = DATA_PATH . '/favicons/'; +$default_favicon = PUBLIC_PATH . '/themes/icons/default_favicon.ico'; + +function download_favicon($website, $dest) { + global $favicons_dir, $default_favicon; + + syslog(LOG_INFO, 'FreshRSS Favicon discovery GET ' . $website); + $favicon_getter = new \Favicon\Favicon(); + $favicon_getter->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); + } + + return false; +} |
