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
2013-06-29 03:50:15 +02:00
namespace PicoFeed\Parsers;
2013-04-05 05:34:07 +02:00
2013-06-29 03:50:15 +02:00
class Atom extends \PicoFeed\Parser
2013-04-05 05:34:07 +02:00
{
public function execute()
{
\libxml_use_internal_errors(true);
$xml = \simplexml_load_string($this->content);
if ($xml === false) {
\PicoFeed\Logging::log($this->getXmlErrors());
2013-04-05 05:34:07 +02:00
return false;
}
$this->url = $this->getUrl($xml);
$this->title = $this->stripWhiteSpace((string) $xml->title);
2013-04-05 05:34:07 +02:00
$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 = $this->stripWhiteSpace((string) $entry->title);
2013-04-05 05:34:07 +02:00
$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'];
}
}