Skip to content

Commit

Permalink
Unify link tag for RSS & Atom into $url property (#20)
Browse files Browse the repository at this point in the history
In rss we have tag <link>https://example.com/articles/some-amazing-article</link>,
but in Atom we have <link href="https://example.com/articles/some-amazing-article"/>.
So, lets extract it from href attr & put into `url` property.
  • Loading branch information
alek13 authored and dg committed Dec 3, 2020
1 parent 18f00ab commit 2310248
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ the information from the channel is easy:
```php
echo 'Title: ', $rss->title;
echo 'Description: ', $rss->description;
echo 'Link: ', $rss->link;
echo 'Link: ', $rss->url;

foreach ($rss->item as $item) {
echo 'Title: ', $item->title;
echo 'Link: ', $item->link;
echo 'Link: ', $item->url;
echo 'Timestamp: ', $item->timestamp;
echo 'Description ', $item->description;
echo 'HTML encoded content: ', $item->{'content:encoded'};
Expand Down
6 changes: 4 additions & 2 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ private static function fromRss(SimpleXMLElement $xml)
// converts namespaces to dotted tags
self::adjustNamespaces($item);

// generate 'timestamp' tag
// generate 'url' & 'timestamp' tags
$item->url = (string) $item->link;
if (isset($item->{'dc:date'})) {
$item->timestamp = strtotime($item->{'dc:date'});
} elseif (isset($item->pubDate)) {
Expand All @@ -102,8 +103,9 @@ private static function fromAtom(SimpleXMLElement $xml)
throw new FeedException('Invalid feed.');
}

// generate 'timestamp' tag
// generate 'url' & 'timestamp' tags
foreach ($xml->entry as $entry) {
$entry->url = (string) $entry->link['href'];
$entry->timestamp = strtotime($entry->updated);
}
$feed = new self;
Expand Down

0 comments on commit 2310248

Please sign in to comment.