minor improvements

- enable debug logging for image proxy
- show enclosure image only if no article content exists
- do not store empty favicons
- fix typo in get_item_favicons (worked anyway since get_favicons
  returned all known favicons instead)
This commit is contained in:
Mathias Kresin 2015-01-09 14:43:45 +01:00
parent 9c58f2235c
commit cfaa25f667
3 changed files with 24 additions and 15 deletions

View File

@ -16,25 +16,30 @@ use PicoFeed\Client\InvalidUrlException;
const LIMIT_ALL = -1; const LIMIT_ALL = -1;
// Download and store the favicon // Store the favicon
function fetch_favicon($feed_id, $site_url) function store_favicon($feed_id, $link, $icon)
{ {
$favicon = new Favicon;
return Database::get('db') return Database::get('db')
->table('favicons') ->table('favicons')
->save(array( ->save(array(
'feed_id' => $feed_id, 'feed_id' => $feed_id,
'link' => $favicon->find($site_url), 'link' => $link,
'icon' => $favicon->getDataUri(), 'icon' => $icon,
)); ));
} }
// Refresh favicon // Download favicon
function refresh_favicon($feed_id, $site_url) function fetch_favicon($feed_id, $site_url)
{ {
if (Config\get('favicons') == 1 && ! has_favicon($feed_id)) { if (Config\get('favicons') == 1 && ! has_favicon($feed_id)) {
fetch_favicon($feed_id, $site_url); $favicon = new Favicon;
$link = $favicon->find($site_url);
$icon = $favicon->getDataUri();
if ($icon !== '') {
store_favicon($feed_id, $link, $icon);
}
} }
} }
@ -63,7 +68,7 @@ function get_item_favicons(array $items)
$feed_ids = array(); $feed_ids = array();
foreach ($items as $item) { foreach ($items as $item) {
$feeds_ids[] = $item['feed_id']; $feed_ids[] = $item['feed_id'];
} }
return get_favicons($feed_ids); return get_favicons($feed_ids);
@ -184,7 +189,7 @@ function create($url, $enable_grabber = false, $force_rtl = false)
$feed_id = $db->getConnection()->getLastId(); $feed_id = $db->getConnection()->getLastId();
Item\update_all($feed_id, $feed->getItems()); Item\update_all($feed_id, $feed->getItems());
refresh_favicon($feed_id, $feed->getSiteUrl()); fetch_favicon($feed_id, $feed->getSiteUrl());
Config\write_debug(); Config\write_debug();
@ -256,7 +261,7 @@ function refresh($feed_id)
update_cache($feed_id, $resource->getLastModified(), $resource->getEtag()); update_cache($feed_id, $resource->getLastModified(), $resource->getEtag());
Item\update_all($feed_id, $feed->getItems()); Item\update_all($feed_id, $feed->getItems());
refresh_favicon($feed_id, $feed->getSiteUrl()); fetch_favicon($feed_id, $feed->getSiteUrl());
} }
update_parsing_error($feed_id, 0); update_parsing_error($feed_id, 0);

View File

@ -13,12 +13,16 @@ function download($url)
$client->setUserAgent(Config\HTTP_USER_AGENT); $client->setUserAgent(Config\HTTP_USER_AGENT);
$client->execute($url); $client->execute($url);
return array( $content = array(
$client->getContent(), $client->getContent(),
$client->getContentType(), $client->getContentType(),
); );
} }
catch (ClientException $e) { catch (ClientException $e) {
return array(false, false); $content = array(false, false);
} }
Config\write_debug();
return $content;
} }

View File

@ -76,7 +76,7 @@
<video controls> <video controls>
<source src="<?= $item['enclosure'] ?>" type="<?= $item['enclosure_type'] ?>"> <source src="<?= $item['enclosure'] ?>" type="<?= $item['enclosure_type'] ?>">
</video> </video>
<?php elseif (strpos($item['enclosure_type'], 'image') !== false): ?> <?php elseif (strpos($item['enclosure_type'], 'image') !== false && $item['content'] === ''): ?>
<?php if ($image_proxy_enabled): ?> <?php if ($image_proxy_enabled): ?>
<img src="?action=proxy&amp;url=<?= urlencode($item['enclosure']) ?>" alt="enclosure"/> <img src="?action=proxy&amp;url=<?= urlencode($item['enclosure']) ?>" alt="enclosure"/>
<?php else: ?> <?php else: ?>