Skip to content

Commit

Permalink
Quick and dirty hack for id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Guillot committed Dec 18, 2013
1 parent 1d3f58c commit bf1d96a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/PicoFeed/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions lib/PicoFeed/Parsers/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ public function execute()
foreach ($xml->entry as $entry) {

if (isset($entry->author->name)) {

$author = (string) $entry->author->name;
}

$id = (string) $entry->id;

$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;
Expand Down
2 changes: 1 addition & 1 deletion lib/PicoFeed/Parsers/Rss10.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/PicoFeed/Parsers/Rss20.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bf1d96a

Please sign in to comment.