From 21dc4ceace513a0d6cd934f5fc4bb9cc643bb570 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 27 Apr 2013 22:33:14 +0200 Subject: Fix issue #64 : stockage des favicons en local --- app/layout/aside_feed.phtml | 2 +- app/layout/aside_flux.phtml | 2 +- app/models/Feed.php | 10 ++++++++++ app/views/index/index.phtml | 2 +- lib/lib_rss.php | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index 4be37868d..ec4993a70 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -43,7 +43,7 @@ feeds as $feed) { ?>
  • - + name (); ?>
  • diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 60fcbe457..d2e5341e3 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -87,7 +87,7 @@ nbNotRead (); ?> - + 0 ? '' : ''; ?> 0 ? '(' . $not_read . ') ' : ''; ?> diff --git a/app/models/Feed.php b/app/models/Feed.php index 08cf7425f..97cbe55d1 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -77,6 +77,16 @@ class Feed extends Model { $feedDAO = new FeedDAO (); return $feedDAO->countNotRead ($this->id ()); } + public function favicon () { + $file = '/data/favicons/' . $this->id () . '.ico'; + + $favicon_url = Url::display ($file); + if (!file_exists (PUBLIC_PATH . $file)) { + $favicon_url = dowload_favicon ($this->website (), $this->id ()); + } + + return $favicon_url; + } public function _id ($value) { $this->id = $value; diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index a7b67bcbc..c9be7169d 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -49,7 +49,7 @@ if (isset ($this->entryPaginator)) { feed (true); ?> -
  • name (); ?>
  • +
  • name (); ?>
  • title (); ?>
  • date (); ?>
  • diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 76c304064..e004b7498 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -152,3 +152,41 @@ function get_content_by_parsing ($url, $path) { throw new Exception (); } } + +/* Télécharge le favicon d'un site, le place sur le serveur et retourne l'URL */ +function dowload_favicon ($website, $id) { + $url = 'http://g.etfv.co/' . $website; + $favicons_dir = PUBLIC_PATH . '/data/favicons'; + $dest = $favicons_dir . '/' . $id . '.ico'; + $favicon_url = '/data/favicons/' . $id . '.ico'; + + if (!is_dir ($favicons_dir)) { + if (!mkdir ($favicons_dir, 0755, true)) { + return $url; + } + } + + if (!file_exists ($dest)) { + $c = curl_init ($url); + curl_setopt ($c, CURLOPT_HEADER, false); + curl_setopt ($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($c, CURLOPT_BINARYTRANSFER, true); + $imgRaw = curl_exec ($c); + + if (curl_getinfo ($c, CURLINFO_HTTP_CODE) == 200) { + $file = fopen ($dest, 'w'); + if ($file === false) { + return $url; + } + + fwrite ($file, $imgRaw); + fclose ($file); + } else { + return $url; + } + + curl_close ($c); + } + + return $favicon_url; +} -- cgit v1.2.3