$this->title, 'published_on' => $this->publishedOn, 'updated_on' => $this->updatedOn, 'content' => $this->content, 'is_read' => 0 ]; } /** * Construct a feed item from an Atom feed's `` tag * * @param DOMNode $node The XML node from which a feed item should be constructed * @return static A feed item constructed from the given node */ public static function fromAtom(DOMNode $node): static { $guid = Feed::atomValue($node, 'id'); $link = ''; foreach ($node->getElementsByTagName('link') as $linkElt) { if ($linkElt->hasAttributes()) { $relAttr = $linkElt->attributes->getNamedItem('rel'); if ($relAttr && $relAttr->value == 'alternate') { $link = $linkElt->attributes->getNamedItem('href')->value; break; } } } if ($link == '' && str_starts_with($guid, 'http')) $link = $guid; $item = new static(); $item->guid = $guid; $item->title = Feed::atomValue($node, 'title'); $item->link = $link; $item->publishedOn = Data::formatDate(Feed::atomValue($node, 'published')); $item->updatedOn = Data::formatDate(Feed::atomValue($node, 'updated')); $item->content = Feed::atomValue($node, 'content'); return $item; } /** * Construct a feed item from an RSS feed's `` tag * * @param DOMNode $node The XML node from which a feed item should be constructed * @return static A feed item constructed from the given node */ public static function fromRSS(DOMNode $node): static { $itemGuid = Feed::rssValue($node, 'guid'); $updNodes = $node->getElementsByTagNameNS(Feed::ATOM_NS, 'updated'); $encNodes = $node->getElementsByTagNameNS(Feed::CONTENT_NS, 'encoded'); $item = new static(); $item->guid = $itemGuid == 'guid not found' ? Feed::rssValue($node, 'link') : $itemGuid; $item->title = Feed::rssValue($node, 'title'); $item->link = Feed::rssValue($node, 'link'); $item->publishedOn = Data::formatDate(Feed::rssValue($node, 'pubDate')); $item->updatedOn = Data::formatDate($updNodes->length > 0 ? $updNodes->item(0)->textContent : null); $item->content = $encNodes->length > 0 ? $encNodes->item(0)->textContent : Feed::rssValue($node, 'description'); return $item; } }