Update PicoFeed (improve feed writers and opml import)

This commit is contained in:
Frédéric Guillot 2013-08-15 20:22:56 -04:00
parent 06b4d87a06
commit 5d78960212
3 changed files with 46 additions and 23 deletions

View File

@ -51,6 +51,7 @@ class Import
else if ((isset($item['text']) || isset($item['title'])) && isset($item['xmlUrl'])) {
$entry = new \StdClass;
$entry->category = isset($tree['title']) ? (string) $tree['title'] : (string) $tree['text'];
$entry->title = isset($item['title']) ? (string) $item['title'] : (string) $item['text'];
$entry->feed_url = (string) $item['xmlUrl'];
$entry->site_url = isset($item['htmlUrl']) ? (string) $item['htmlUrl'] : $entry->feed_url;

View File

@ -35,10 +35,14 @@ class Atom extends \PicoFeed\Writer
$feed->appendChild($generator);
// <title/>
$feed->appendChild($this->dom->createElement('title', $this->title));
$title = $this->dom->createElement('title');
$title->appendChild($this->dom->createTextNode($this->title));
$feed->appendChild($title);
// <id/>
$feed->appendChild($this->dom->createElement('id', $this->site_url));
$id = $this->dom->createElement('id');
$id->appendChild($this->dom->createTextNode($this->site_url));
$feed->appendChild($id);
// <updated/>
$this->addUpdated($feed, isset($this->updated) ? $this->updated : '');
@ -60,16 +64,14 @@ class Atom extends \PicoFeed\Writer
$entry = $this->dom->createElement('entry');
// <title/>
$entry->appendChild($this->dom->createElement('title', $item['title']));
$title = $this->dom->createElement('title');
$title->appendChild($this->dom->createTextNode($item['title']));
$entry->appendChild($title);
// <id/>
if (isset($item['id'])) {
$entry->appendChild($this->dom->createElement('id', $item['id']));
}
else {
$entry->appendChild($this->dom->createElement('id', $item['url']));
}
$id = $this->dom->createElement('id');
$id->appendChild($this->dom->createTextNode(isset($item['id']) ? $item['id'] : $item['url']));
$entry->appendChild($id);
// <updated/>
$this->addUpdated($entry, isset($item['updated']) ? $item['updated'] : '');
@ -84,7 +86,9 @@ class Atom extends \PicoFeed\Writer
// <summary/>
if (isset($item['summary'])) {
$entry->appendChild($this->dom->createElement('summary', $item['summary']));
$summary = $this->dom->createElement('summary');
$summary->appendChild($this->dom->createTextNode($item['summary']));
$entry->appendChild($summary);
}
// <content/>
@ -136,17 +140,20 @@ class Atom extends \PicoFeed\Writer
$author = $this->dom->createElement('author');
if (isset($values['name'])) {
$name = $this->dom->createElement('name', $values['name']);
$name = $this->dom->createElement('name');
$name->appendChild($this->dom->createTextNode($values['name']));
$author->appendChild($name);
}
if (isset($values['email'])) {
$email = $this->dom->createElement('email', $values['email']);
$email = $this->dom->createElement('email');
$email->appendChild($this->dom->createTextNode($values['email']));
$author->appendChild($email);
}
if (isset($values['url'])) {
$uri = $this->dom->createElement('uri', $values['url']);
$uri = $this->dom->createElement('uri');
$uri->appendChild($this->dom->createTextNode($values['url']));
$author->appendChild($uri);
}

View File

@ -38,10 +38,14 @@ class Rss20 extends \PicoFeed\Writer
$channel->appendChild($generator);
// <title/>
$channel->appendChild($this->dom->createElement('title', $this->title));
$title = $this->dom->createElement('title');
$title->appendChild($this->dom->createTextNode($this->title));
$channel->appendChild($title);
// <description/>
$channel->appendChild($this->dom->createElement('description', isset($this->description) ? $this->description : $this->title));
$description = $this->dom->createElement('description');
$description->appendChild($this->dom->createTextNode(isset($this->description) ? $this->description : $this->title));
$channel->appendChild($description);
// <pubDate/>
$this->addPubDate($channel, isset($this->updated) ? $this->updated : '');
@ -54,7 +58,9 @@ class Rss20 extends \PicoFeed\Writer
$channel->appendChild($link);
// <link/>
$channel->appendChild($this->dom->createElement('link', $this->site_url));
$link = $this->dom->createElement('link');
$link->appendChild($this->dom->createTextNode($this->site_url));
$channel->appendChild($link);
// <webMaster/>
if (isset($this->author)) $this->addAuthor($channel, 'webMaster', $this->author);
@ -67,20 +73,26 @@ class Rss20 extends \PicoFeed\Writer
$entry = $this->dom->createElement('item');
// <title/>
$entry->appendChild($this->dom->createElement('title', $item['title']));
$title = $this->dom->createElement('title');
$title->appendChild($this->dom->createTextNode($item['title']));
$entry->appendChild($title);
// <link/>
$entry->appendChild($this->dom->createElement('link', $item['url']));
$link = $this->dom->createElement('link');
$link->appendChild($this->dom->createTextNode($item['url']));
$entry->appendChild($link);
// <guid/>
if (isset($item['id'])) {
$guid = $this->dom->createElement('guid', $item['id']);
$guid = $this->dom->createElement('guid');
$guid->setAttribute('isPermaLink', 'false');
$guid->appendChild($this->dom->createTextNode($item['id']));
$entry->appendChild($guid);
}
else {
$guid = $this->dom->createElement('guid', $item['url']);
$guid = $this->dom->createElement('guid');
$guid->setAttribute('isPermaLink', 'true');
$guid->appendChild($this->dom->createTextNode($item['url']));
$entry->appendChild($guid);
}
@ -89,7 +101,9 @@ class Rss20 extends \PicoFeed\Writer
// <description/>
if (isset($item['summary'])) {
$entry->appendChild($this->dom->createElement('description', $item['summary']));
$description = $this->dom->createElement('description');
$description->appendChild($this->dom->createTextNode($item['summary']));
$entry->appendChild($description);
}
// <content/>
@ -134,7 +148,8 @@ class Rss20 extends \PicoFeed\Writer
if ($value && isset($values['name'])) $value .= ' ('.$values['name'].')';
if ($value) {
$author = $this->dom->createElement($tag, $value);
$author = $this->dom->createElement($tag);
$author->appendChild($this->dom->createTextNode($value));
$xml->appendChild($author);
}
}