From bf1d96af0b526a210c3aa4a688c68402adc8d9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Tue, 17 Dec 2013 20:56:26 -0500 Subject: [PATCH] Quick and dirty hack for id generation --- lib/PicoFeed/Parser.php | 13 +++++++++++++ lib/PicoFeed/Parsers/Atom.php | 3 +-- lib/PicoFeed/Parsers/Rss10.php | 2 +- lib/PicoFeed/Parsers/Rss20.php | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/PicoFeed/Parser.php b/lib/PicoFeed/Parser.php index 3af694e..8e8d89f 100644 --- a/lib/PicoFeed/Parser.php +++ b/lib/PicoFeed/Parser.php @@ -159,4 +159,17 @@ public function getValidDate($format, $value) return 0; } + + + // Hardcoded list of hostname/token to exclude from id generation + public function isExcludedFromId($url) + { + $exclude_list = array('ap.org'); + + foreach ($exclude_list as $token) { + if (strpos($url, $token) !== false) return true; + } + + return false; + } } diff --git a/lib/PicoFeed/Parsers/Atom.php b/lib/PicoFeed/Parsers/Atom.php index 59b3719..31583f5 100644 --- a/lib/PicoFeed/Parsers/Atom.php +++ b/lib/PicoFeed/Parsers/Atom.php @@ -26,7 +26,6 @@ public function execute() foreach ($xml->entry as $entry) { if (isset($entry->author->name)) { - $author = (string) $entry->author->name; } @@ -34,7 +33,7 @@ public function execute() $item = new \StdClass; $item->url = $this->getUrl($entry); - $item->id = $this->generateId($id !== $item->url ? $id : $item->url, $this->url); + $item->id = $this->generateId($id !== $item->url ? $id : $item->url, $this->isExcludedFromId($this->url) ? '' : $this->url); $item->title = $this->stripWhiteSpace((string) $entry->title); $item->updated = $this->parseDate((string) $entry->updated); $item->author = $author; diff --git a/lib/PicoFeed/Parsers/Rss10.php b/lib/PicoFeed/Parsers/Rss10.php index 43c0b3c..b6890e7 100644 --- a/lib/PicoFeed/Parsers/Rss10.php +++ b/lib/PicoFeed/Parsers/Rss10.php @@ -72,7 +72,7 @@ public function execute() if (empty($item->title)) $item->title = $item->url; - $item->id = $this->generateId($item->url, $this->url); + $item->id = $this->generateId($item->url, $this->isExcludedFromId($this->url) ? '' : $this->url); $item->content = $this->filterHtml($item->content, $item->url); $this->items[] = $item; } diff --git a/lib/PicoFeed/Parsers/Rss20.php b/lib/PicoFeed/Parsers/Rss20.php index 1a0f3f0..8196b30 100644 --- a/lib/PicoFeed/Parsers/Rss20.php +++ b/lib/PicoFeed/Parsers/Rss20.php @@ -98,11 +98,11 @@ public function execute() if (isset($entry->guid) && isset($entry->guid['isPermaLink']) && (string) $entry->guid['isPermaLink'] != 'false') { $id = (string) $entry->guid; - $item->id = $this->generateId($id !== '' && $id !== $item->url ? $id : $item->url, $this->url); + $item->id = $this->generateId($id !== '' && $id !== $item->url ? $id : $item->url, $this->isExcludedFromId($this->url) ? '' : $this->url); } else { - $item->id = $this->generateId($item->url, $this->url); + $item->id = $this->generateId($item->url, $this->isExcludedFromId($this->url) ? '' : $this->url); } if (empty($item->title)) $item->title = $item->url;