WIP on document conversion
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use DOMNode;
|
||||
|
||||
/**
|
||||
* Information for a feed item
|
||||
@@ -23,13 +26,30 @@ class FeedItem {
|
||||
/** @var string The content for the item */
|
||||
public string $content = '';
|
||||
|
||||
/**
|
||||
* Get the fields needed to update the item in the database
|
||||
*
|
||||
* @return array The fields needed tu update an item
|
||||
*/
|
||||
public function patchFields(): array
|
||||
{
|
||||
return [
|
||||
'title' => $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 `<entry>` tag
|
||||
*
|
||||
* @param DOMNode $node The XML node from which a feed item should be constructed
|
||||
* @return FeedItem A feed item constructed from the given node
|
||||
* @return static A feed item constructed from the given node
|
||||
*/
|
||||
public static function fromAtom(DOMNode $node): FeedItem {
|
||||
public static function fromAtom(DOMNode $node): static
|
||||
{
|
||||
$guid = Feed::atomValue($node, 'id');
|
||||
$link = '';
|
||||
foreach ($node->getElementsByTagName('link') as $linkElt) {
|
||||
@@ -43,7 +63,7 @@ class FeedItem {
|
||||
}
|
||||
if ($link == '' && str_starts_with($guid, 'http')) $link = $guid;
|
||||
|
||||
$item = new FeedItem();
|
||||
$item = new static();
|
||||
$item->guid = $guid;
|
||||
$item->title = Feed::atomValue($node, 'title');
|
||||
$item->link = $link;
|
||||
@@ -58,14 +78,15 @@ class FeedItem {
|
||||
* Construct a feed item from an RSS feed's `<item>` tag
|
||||
*
|
||||
* @param DOMNode $node The XML node from which a feed item should be constructed
|
||||
* @return FeedItem A feed item constructed from the given node
|
||||
* @return static A feed item constructed from the given node
|
||||
*/
|
||||
public static function fromRSS(DOMNode $node): FeedItem {
|
||||
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 FeedItem();
|
||||
$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');
|
||||
|
||||
Reference in New Issue
Block a user