Update of PicoFeed

This commit is contained in:
Frederic Guillot 2013-03-20 00:19:12 -04:00
parent 4dc72773dd
commit d9a47f71d6
3 changed files with 96 additions and 13 deletions

View File

@ -22,7 +22,7 @@ class Import
$xml = new \SimpleXMLElement(trim($this->content)); $xml = new \SimpleXMLElement(trim($this->content));
if ($xml->getName() !== 'opml') { if ($xml->getName() !== 'opml' || ! isset($xml->body)) {
return false; return false;
} }
@ -40,22 +40,25 @@ class Import
public function parseEntries($tree) public function parseEntries($tree)
{ {
if (isset($tree->outline)) {
foreach ($tree->outline as $item) { foreach ($tree->outline as $item) {
if (isset($item['type']) && strtolower($item['type']) === 'folder' && isset($item->outline)) { if (isset($item->outline)) {
$this->parseEntries($item); $this->parseEntries($item);
} }
else if (isset($item['type']) && strtolower($item['type']) === 'rss') { else if (isset($item['text']) && isset($item['xmlUrl']) && isset($item['htmlUrl'])) {
$entry = new \StdClass; $entry = new \StdClass;
$entry->title = (string) $item['text']; $entry->title = isset($item['title']) ? (string) $item['title'] : (string) $item['text'];
$entry->site_url = (string) $item['htmlUrl']; $entry->site_url = (string) $item['htmlUrl'];
$entry->feed_url = (string) $item['xmlUrl']; $entry->feed_url = (string) $item['xmlUrl'];
$entry->type = isset($item['version']) ? (string) $item['version'] : (string) $item['type']; $entry->type = isset($item['version']) ? (string) $item['version'] : isset($item['type']) ? (string) $item['type'] : 'rss';
$entry->description = (string) $item['description']; $entry->description = isset($item['description']) ? (string) $item['description'] : $entry->title;
$this->items[] = $entry; $this->items[] = $entry;
} }
} }
} }
}
} }

View File

@ -185,3 +185,79 @@ class Rss20 extends Parser
return $this; return $this;
} }
} }
class Rss10 extends Parser
{
public function execute()
{
try {
\libxml_use_internal_errors(true);
$xml = new \SimpleXMLElement($this->content);
$ns = $xml->getNamespaces(true);
$this->title = (string) $xml->channel->title;
$this->url = (string) $xml->channel->link;
$this->id = $this->url;
if (isset($ns['dc'])) {
$ns_dc = $xml->channel->children($ns['dc']);
$this->updated = isset($ns_dc->date) ? strtotime($ns_dc->date) : time();
}
else {
$this->updated = time();
}
foreach ($xml->item as $entry) {
$author = '';
$content = '';
$pubdate = '';
$link = '';
if (isset($ns['feedburner'])) {
$ns_fb = $entry->children($ns['feedburner']);
$link = $ns_fb->origLink;
}
if (isset($ns['dc'])) {
$ns_dc = $entry->children($ns['dc']);
$author = (string) $ns_dc->creator;
$pubdate = (string) $ns_dc->date;
}
if (isset($ns['content'])) {
$ns_content = $entry->children($ns['content']);
$content = (string) $ns_content->encoded;
}
if ($content === '' && isset($entry->description)) {
$content = (string) $entry->description;
}
$item = new \StdClass;
$item->title = (string) $entry->title;
$item->url = $link ?: (string) $entry->link;
$item->id = $item->url;
$item->updated = $pubdate ? strtotime($pubdate) : time();
$item->content = $this->filterHtml($content, $item->url);
$item->author = $author ?: (string) $xml->channel->webMaster;
$this->items[] = $item;
}
}
catch (\Exception $e) {
}
return $this;
}
}

View File

@ -70,6 +70,10 @@ class Reader
return new Rss20($this->content); return new Rss20($this->content);
} }
else if (strpos($first_tag, '<rdf:') !== false && strpos($first_tag, 'xmlns="http://purl.org/rss/1.0/"') !== false) {
return new Rss10($this->content);
}
else if ($discover === true) { else if ($discover === true) {
return false; return false;