Fix issue #64 : stockage des favicons en local

This commit is contained in:
Marien Fressinaud
2013-04-27 22:33:14 +02:00
parent 0e95494e29
commit 21dc4ceace
5 changed files with 51 additions and 3 deletions

View File

@@ -43,7 +43,7 @@
<?php foreach ($this->feeds as $feed) { ?>
<li class="item<?php echo ($this->flux && $this->flux->id () == $feed->id ()) ? ' active' : ''; ?>">
<a href="<?php echo _url ('configure', 'feed', 'id', $feed->id ()); ?>">
<img class="favicon" src="http://g.etfv.co/<?php echo $feed->website (); ?>" alt="" />
<img class="favicon" src="<?php echo $feed->favicon (); ?>" alt="" />
<?php echo $feed->name (); ?>
</a>
</li>

View File

@@ -87,7 +87,7 @@
<?php $not_read = $feed->nbNotRead (); ?>
<img class="favicon" src="http://g.etfv.co/<?php echo $feed->website (); ?>" alt="" />
<img class="favicon" src="<?php echo $feed->favicon (); ?>" alt="" />
<?php echo $not_read > 0 ? '<b>' : ''; ?>
<a class="feed" href="<?php echo _url ('index', 'index', 'get', 'f_' . $feed->id ()); ?>">
<?php echo $not_read > 0 ? '(' . $not_read . ') ' : ''; ?>

View File

@@ -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;

View File

@@ -49,7 +49,7 @@ if (isset ($this->entryPaginator)) {
</li>
<?php } ?>
<?php $feed = $item->feed (true); ?>
<li class="item website"><a href="<?php echo _url ('index', 'index', 'get', 'f_' . $feed->id ()); ?>"><img class="favicon" src="http://g.etfv.co/<?php echo $feed->website (); ?>" alt="" /> <span><?php echo $feed->name (); ?></span></a></li>
<li class="item website"><a href="<?php echo _url ('index', 'index', 'get', 'f_' . $feed->id ()); ?>"><img class="favicon" src="<?php echo $feed->favicon (); ?>" alt="" /> <span><?php echo $feed->name (); ?></span></a></li>
<li class="item title"><?php echo $item->title (); ?></li>
<li class="item date"><?php echo $item->date (); ?></li>
<li class="item link"><a target="_blank" href="<?php echo $item->link (); ?>">&nbsp;</a></li>

View File

@@ -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;
}