4
0

favicons.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. include(LIB_PATH . '/Favicon/Favicon.php');
  3. include(LIB_PATH . '/Favicon/DataAccess.php');
  4. $favicons_dir = DATA_PATH . '/favicons/';
  5. $default_favicon = PUBLIC_PATH . '/themes/icons/default_favicon.ico';
  6. function download_favicon($website, $dest) {
  7. global $favicons_dir, $default_favicon;
  8. syslog(LOG_INFO, 'FreshRSS Favicon discovery GET ' . $website);
  9. $favicon_getter = new \Favicon\Favicon();
  10. $favicon_getter->setCacheDir($favicons_dir);
  11. $favicon_url = $favicon_getter->get($website);
  12. if ($favicon_url === false) {
  13. return @copy($default_favicon, $dest);
  14. }
  15. syslog(LOG_INFO, 'FreshRSS Favicon GET ' . $favicon_url);
  16. $c = curl_init($favicon_url);
  17. curl_setopt($c, CURLOPT_HEADER, false);
  18. curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  19. curl_setopt($c, CURLOPT_BINARYTRANSFER, true);
  20. curl_setopt($c, CURLOPT_USERAGENT, 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')');
  21. $img_raw = curl_exec($c);
  22. $status_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
  23. curl_close($c);
  24. if ($status_code === 200) {
  25. $file = fopen($dest, 'w');
  26. if ($file !== false) {
  27. fwrite($file, $img_raw);
  28. fclose($file);
  29. return true;
  30. }
  31. } else {
  32. syslog(LOG_WARNING, 'FreshRSS Favicon GET ' . $favicon_url . ' error ' . $status_code);
  33. }
  34. return false;
  35. }