Quick and dirty hack for id generation

This commit is contained in:
Frédéric Guillot 2013-12-17 20:56:53 -05:00
parent 9f699e46b5
commit d92f201fdc
4 changed files with 17 additions and 5 deletions

View File

@ -159,4 +159,17 @@ abstract class Parser
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;
}
}

View File

@ -26,7 +26,6 @@ class Atom extends \PicoFeed\Parser
foreach ($xml->entry as $entry) {
if (isset($entry->author->name)) {
$author = (string) $entry->author->name;
}
@ -34,7 +33,7 @@ class Atom extends \PicoFeed\Parser
$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;

View File

@ -72,7 +72,7 @@ class Rss10 extends \PicoFeed\Parser
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;
}

View File

@ -98,11 +98,11 @@ class Rss20 extends \PicoFeed\Parser
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;