Improve enclosure support

This commit is contained in:
Frédéric Guillot 2014-02-17 22:04:49 -05:00
parent 2874d16a5d
commit 74d8d361ee
10 changed files with 74 additions and 20 deletions

View File

@ -63,6 +63,7 @@ People who sent a pull-request, report a bug, make a new theme or share a super
- MonsieurPaulLeBoulanger: https://github.com/MonsieurPaulLeBoulanger
- Necku: https://github.com/Necku
- Nicolas Dewaele: http://adminrezo.fr/
- Pcwalden: https://github.com/pcwalden
- Silvus: https://github.com/Silvus
- Skasi7: https://github.com/skasi7
- Thiriot Christophe: https://github.com/doubleface

View File

@ -1,6 +1,7 @@
<?php
return array(
'attachment' => 'pièce jointe',
'When there is nothing to read, redirect me to this page' => 'Quand il n\'y a rien à lire, redirigez moi vers cette page',
'Subscription page' => 'Page des abonnements',
'History page' => 'Historique de lecture',

View File

@ -19,6 +19,7 @@ function get_everything()
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.feed_id',
'items.status',
@ -43,6 +44,7 @@ function get_everything_since($timestamp)
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.feed_id',
'items.status',
@ -78,6 +80,7 @@ function get_all($status, $offset = null, $limit = null, $order_column = 'update
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.feed_id',
'items.status',
@ -123,6 +126,7 @@ function get_bookmarks($offset = null, $limit = null)
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.status',
'items.content',
@ -160,6 +164,7 @@ function get_all_by_feed($feed_id, $offset = null, $limit = null, $order_column
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.feed_id',
'items.status',
'items.content',
@ -426,7 +431,8 @@ function update_all($feed_id, array $items, $grabber = false)
'content' => $nocontent ? '' : $item->content,
'status' => 'unread',
'feed_id' => $feed_id,
'enclosure' => isset($item->enclosure) ? $item->enclosure : NULL
'enclosure' => isset($item->enclosure) ? $item->enclosure : null,
'enclosure_type' => isset($item->enclosure_type) ? $item->enclosure_type : null,
));
}
else {

View File

@ -6,8 +6,10 @@ namespace Schema;
function version_21($pdo)
{
$pdo->exec('ALTER TABLE items ADD COLUMN enclosure TEXT');
$pdo->exec('ALTER TABLE items ADD COLUMN enclosure_type TEXT');
}
function version_20($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN redirect_nothing_to_read TEXT DEFAULT "feeds"');

View File

@ -63,14 +63,20 @@
<a href="?action=enable-grabber-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable full content') ?></a>
<?php endif ?>
</li>
<li class="hide-mobile">
<?php if ($feed['enabled']): ?>
<li class="hide-mobile">
<a href="?action=confirm-disable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('disable') ?></a>
<a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a>
<?php else: ?>
<a href="?action=enable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable') ?></a>
<?php endif ?>
</li>
<li class="hide-mobile">
<a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a>
</li>
<?php else: ?>
<li>
<a href="?action=enable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable') ?></a>
</li>
<?php endif ?>
<li class="hide-mobile">
<a href="?action=edit-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('edit') ?></a>
</li>

View File

@ -35,9 +35,9 @@
<li class="hide-mobile">
<a href="<?= $item['url'] ?>" id="original-<?= $item['id'] ?>" rel="noreferrer" target="_blank" data-item-id="<?= $item['id'] ?>"><?= t('original link') ?></a>
</li>
<?php if (isset($item['enclosure']) && ! is_null($item['enclosure'])): ?>
<li class="hide-mobile">
<a href="<?= $item['enclosure'] ?>" rel="noreferrer" target="_blank">multimedia 🔉</a>
<?php if ($item['enclosure']): ?>
<li>
<a href="<?= $item['enclosure'] ?>" rel="noreferrer" target="_blank"><?= t('media') ?></a>
</li>
<?php endif ?>
<?= \PicoTools\Template\load('bookmark_links', array('item' => $item, 'menu' => $menu, 'offset' => $offset, 'source' => '')) ?>

View File

@ -64,6 +64,11 @@
<li class="hide-mobile">
<?= dt('%e %B %Y %k:%M', $item['updated']) ?>
</li>
<?php if ($item['enclosure']): ?>
<li>
<a href="<?= $item['enclosure'] ?>" rel="noreferrer" target="_blank"><?= t('attachment') ?></a>
</li>
<?php endif ?>
<li class="hide-mobile">
<span id="download-item"
data-item-id="<?= $item['id'] ?>"
@ -79,6 +84,18 @@
<div id="item-content">
<?= $item['content'] ?>
<?php if ($item['enclosure']): ?>
<?php if (strpos($item['enclosure_type'], 'audio') !== false): ?>
<audio controls>
<source src="<?= $item['enclosure'] ?>" type="<?= $item['enclosure_type'] ?>">
</audio>
<?php elseif (strpos($item['enclosure_type'], 'video') !== false): ?>
<video controls>
<source src="<?= $item['enclosure'] ?>" type="<?= $item['enclosure_type'] ?>">
</video>
<?php endif ?>
<?php endif ?>
</div>
<?php if (isset($item_nav)): ?>

View File

@ -315,7 +315,7 @@ class Filter
}
public function getAbsoluteUrl($path, $url)
public static function getAbsoluteUrl($path, $url)
{
$components = parse_url($url);
@ -358,7 +358,7 @@ class Filter
}
public function isRelativePath($value)
public static function isRelativePath($value)
{
if (strpos($value, 'data:') === 0) return false;
return strpos($value, '://') === false && strpos($value, '//') !== 0;

View File

@ -44,6 +44,19 @@ class Atom extends \PicoFeed\Parser
if (empty($item->title)) $item->title = $item->url;
// Try to find an enclosure
foreach ($entry->link as $link) {
if ((string) $link['rel'] === 'enclosure') {
$item->enclosure = (string) $link['href'];
$item->enclosure_type = (string) $link['type'];
if (\PicoFeed\Filter::isRelativePath($item->enclosure)) {
$item->enclosure = \PicoFeed\Filter::getAbsoluteUrl($item->enclosure, $this->url);
}
break;
}
}
$this->items[] = $item;
}
@ -58,16 +71,13 @@ class Atom extends \PicoFeed\Parser
if (isset($entry->content) && ! empty($entry->content)) {
if (count($entry->content->children())) {
return (string) $entry->content->asXML();
}
else {
return (string) $entry->content;
}
}
else if (isset($entry->summary) && ! empty($entry->summary)) {
return (string) $entry->summary;
}
@ -78,9 +88,7 @@ class Atom extends \PicoFeed\Parser
public function getUrl($xml)
{
foreach ($xml->link as $link) {
if ((string) $link['type'] === 'text/html' || (string) $link['type'] === 'application/xhtml+xml') {
return (string) $link['href'];
}
}

View File

@ -58,16 +58,21 @@ class Rss20 extends \PicoFeed\Parser
$item->author= '';
$item->updated = '';
$item->content = '';
$item->enclosure = '';
$item->enclosure_type = '';
foreach ($namespaces as $name => $url) {
$namespace = $entry->children($namespaces[$name]);
if (! $item->url && ! empty($namespace->origLink)) $item->url = (string) $namespace->origLink;
if (! $item->author && ! empty($namespace->creator)) $item->author = (string) $namespace->creator;
if (! $item->updated && ! empty($namespace->date)) $item->updated = $this->parseDate((string) $namespace->date);
if (! $item->updated && ! empty($namespace->updated)) $item->updated = $this->parseDate((string) $namespace->updated);
if (! $item->content && ! empty($namespace->encoded)) $item->content = (string) $namespace->encoded;
// Get FeedBurner original links
if (! $item->url && ! empty($namespace->origLink)) $item->url = (string) $namespace->origLink;
if (! $item->enclosure && ! empty($namespace->origEnclosureLink)) $item->enclosure = (string) $namespace->origEnclosureLink;
}
if (empty($item->url)) {
@ -112,8 +117,16 @@ class Rss20 extends \PicoFeed\Parser
// if optional enclosure tag with multimedia provided, capture here
if (isset($entry->enclosure)) {
$item->enclosure = (string) $entry->enclosure['url'];
// \PicoFeed\Logging::log(\get_called_class().': recorded enclosure ('.(string) $item->enclosure.')');
if (! $item->enclosure) {
$item->enclosure = isset($entry->enclosure['url']) ? (string) $entry->enclosure['url'] : '';
}
$item->enclosure_type = isset($entry->enclosure['type']) ? (string) $entry->enclosure['type'] : '';
if (\PicoFeed\Filter::isRelativePath($item->enclosure)) {
$item->enclosure = \PicoFeed\Filter::getAbsoluteUrl($item->enclosure, $this->url);
}
}
$item->content = $this->filterHtml($item->content, $item->url);