From 6f2702b256781ab23e3fb7c05a737e4baf3c9ba4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 28 Jun 2013 21:50:15 -0400 Subject: [PATCH] Update of picoFeed --- vendor/PicoFeed/Filter.php | 22 +++++- vendor/PicoFeed/Parsers/Atom.php | 4 +- vendor/PicoFeed/Parsers/Rss10.php | 4 +- vendor/PicoFeed/Parsers/Rss20.php | 4 +- vendor/PicoFeed/Parsers/Rss91.php | 2 +- vendor/PicoFeed/Parsers/Rss92.php | 2 +- vendor/PicoFeed/Reader.php | 31 ++++---- vendor/PicoFeed/Writer.php | 21 ++++++ vendor/PicoFeed/Writers/Atom.php | 121 ++++++++++++++++++++++++++++++ 9 files changed, 187 insertions(+), 24 deletions(-) create mode 100644 vendor/PicoFeed/Writers/Atom.php diff --git a/vendor/PicoFeed/Filter.php b/vendor/PicoFeed/Filter.php index dd6f526..99ce254 100644 --- a/vendor/PicoFeed/Filter.php +++ b/vendor/PicoFeed/Filter.php @@ -257,8 +257,25 @@ class Filter public function getAbsoluteUrl($path, $url) { + //if (! filter_var($url, FILTER_VALIDATE_URL)) return ''; + $components = parse_url($url); + if (! isset($components['scheme'])) $components['scheme'] = 'http'; + + if (! isset($components['host'])) { + + if ($url) { + + $components['host'] = $url; + $components['path'] = '/'; + } + else { + + return ''; + } + } + if ($path{0} === '/') { // Absolute path @@ -267,9 +284,10 @@ class Filter else { // Relative path - $url_path = $components['path']; + $url_path = isset($components['path']) && ! empty($components['path']) ? $components['path'] : '/'; + $length = strlen($url_path); - if ($url_path{strlen($url_path) - 1} !== '/') { + if ($length > 1 && $url_path{$length - 1} !== '/') { $url_path = dirname($url_path).'/'; } diff --git a/vendor/PicoFeed/Parsers/Atom.php b/vendor/PicoFeed/Parsers/Atom.php index ab5b805..05cefda 100644 --- a/vendor/PicoFeed/Parsers/Atom.php +++ b/vendor/PicoFeed/Parsers/Atom.php @@ -1,8 +1,8 @@ content); + return new Parsers\Atom($this->content); } else if (strpos($first_tag, 'content); + return new Parsers\Rss20($this->content); } else if (strpos($first_tag, 'content); + return new Parsers\Rss92($this->content); } else if (strpos($first_tag, 'content); + return new Parsers\Rss91($this->content); } else if (strpos($first_tag, 'content); + return new Parsers\Rss10($this->content); } else if ($discover === true) { @@ -149,18 +149,21 @@ class Reader $link = $nodes->item(0)->getAttribute('href'); - // Relative links - if (strpos($link, 'http') !== 0) { + if (! empty($link)) { - if ($link{0} === '/') $link = substr($link, 1); - if ($this->url{strlen($this->url) - 1} !== '/') $this->url .= '/'; + // Relative links + if (strpos($link, 'http') !== 0) { - $link = $this->url.$link; + if ($link{0} === '/') $link = substr($link, 1); + if ($this->url{strlen($this->url) - 1} !== '/') $this->url .= '/'; + + $link = $this->url.$link; + } + + $this->download($link); + + return true; } - - $this->download($link); - - return true; } } diff --git a/vendor/PicoFeed/Writer.php b/vendor/PicoFeed/Writer.php index e69de29..c9fc8e4 100644 --- a/vendor/PicoFeed/Writer.php +++ b/vendor/PicoFeed/Writer.php @@ -0,0 +1,21 @@ +required_properties as $property) { + + if (! isset($this->$property)) { + + throw new \RuntimeException('Required property missing: '.$property); + } + } + } +} \ No newline at end of file diff --git a/vendor/PicoFeed/Writers/Atom.php b/vendor/PicoFeed/Writers/Atom.php new file mode 100644 index 0000000..084b4f6 --- /dev/null +++ b/vendor/PicoFeed/Writers/Atom.php @@ -0,0 +1,121 @@ +checkRequiredProperties(); + + $dom = new \DomDocument('1.0', 'UTF-8'); + $dom->formatOutput = true; + + // + $feed = $dom->createElement('feed'); + $feed->setAttributeNodeNS(new \DomAttr('xmlns', 'http://www.w3.org/2005/Atom')); + + // + $generator = $dom->createElement('generator', 'PicoFeed'); + $generator->setAttribute('url', 'https://github.com/fguillot/picoFeed'); + $feed->appendChild($generator); + + // + $feed->appendChild($dom->createElement('title', $this->title)); + + // <updated/> + $feed->appendChild($dom->createElement('updated', date(DATE_ATOM, isset($this->updated) ? $this->updated : time()))); + + // <link rel="alternate" type="text/html" href="http://example.org/"/> + $link = $dom->createElement('link'); + $link->setAttribute('rel', 'alternate'); + $link->setAttribute('type', 'text/html'); + $link->setAttribute('href', $this->site_url); + $feed->appendChild($link); + + // <link rel="self" type="application/atom+xml" href="http://example.org/feed.atom"/> + $link = $dom->createElement('link'); + $link->setAttribute('rel', 'self'); + $link->setAttribute('type', 'application/atom+xml'); + $link->setAttribute('href', $this->feed_url); + $feed->appendChild($link); + + // <author/> + if (isset($this->author)) { + + $name = $dom->createElement('name', $this->author); + + $author = $dom->createElement('author'); + $author->appendChild($name); + $feed->appendChild($author); + } + + // <entry/> + foreach ($this->items as $item) { + + $entry = $dom->createElement('entry'); + + // <title/> + $entry->appendChild($dom->createElement('title', $item['title'])); + + // <updated/> + $entry->appendChild($dom->createElement('updated', date(DATE_ATOM, isset($item['updated']) ? $item['updated'] : time()))); + + // <published/> + if (isset($item['published'])) { + $entry->appendChild($dom->createElement('published', date(DATE_ATOM, $item['published']))); + } + + // <link rel="alternate" type="text/html" href="http://example.org/"/> + $link = $dom->createElement('link'); + $link->setAttribute('rel', 'alternate'); + $link->setAttribute('type', 'text/html'); + $link->setAttribute('href', $item['url']); + $entry->appendChild($link); + + // <summary/> + if (isset($item['summary'])) { + $entry->appendChild($dom->createElement('summary', $item['summary'])); + } + + // <content/> + if (isset($item['content'])) { + $content = $dom->createElement('content'); + $content->setAttribute('type', 'html'); + $content->appendChild($dom->createCDATASection($item['content'])); + $entry->appendChild($content); + } + + // <author/> + if (isset($item['author'])) { + + $name = $dom->createElement('name', $item['author']); + + $author = $dom->createElement('author'); + $author->appendChild($name); + + $entry->appendChild($author); + } + + $feed->appendChild($entry); + } + + $dom->appendChild($feed); + + if ($filename) { + $dom->save($filename); + } + else { + return $dom->saveXML(); + } + } +} \ No newline at end of file