miniflux-legacy/vendor/PicoFeed/Parsers/Atom.php

82 lines
2.0 KiB
PHP
Raw Normal View History

2013-04-05 05:34:07 +02:00
<?php
namespace PicoFeed;
class Atom extends Parser
{
public function execute()
{
\libxml_use_internal_errors(true);
$xml = \simplexml_load_string($this->content);
if ($xml === false) {
if ($this->debug) $this->displayXmlErrors();
return false;
}
$this->url = $this->getUrl($xml);
$this->title = (string) $xml->title;
$this->id = (string) $xml->id;
$this->updated = strtotime((string) $xml->updated);
$author = (string) $xml->author->name;
foreach ($xml->entry as $entry) {
if (isset($entry->author->name)) {
$author = $entry->author->name;
}
$item = new \StdClass;
$item->id = (string) $entry->id;
$item->title = (string) $entry->title;
$item->url = $this->getUrl($entry);
$item->updated = strtotime((string) $entry->updated);
$item->author = $author;
$item->content = $this->filterHtml($this->getContent($entry), $item->url);
2013-05-06 03:44:03 +02:00
if (empty($item->title)) $item->title = $item->url;
2013-04-05 05:34:07 +02:00
$this->items[] = $item;
}
return $this;
}
public function getContent($entry)
{
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;
}
return '';
}
public function getUrl($xml)
{
foreach ($xml->link as $link) {
2013-04-13 03:09:05 +02:00
if ((string) $link['type'] === 'text/html' || (string) $link['type'] === 'application/xhtml+xml') {
2013-04-05 05:34:07 +02:00
return (string) $link['href'];
}
}
return (string) $xml->link['href'];
}
}