3

I use SimplePie to parse RSS feeds in php. For pre-processing the result of SimplePie, I need to know if the the link is a permalink or not. The info is stored in this XML element:

<guid isPermaLink="false">FileNr123</guid>

If $items is an instance of SimplePie objet that stands for one RSS feed item, I can use $item->get_permalink to get the permalink. Unfortunately this returns the fileName/guid, even if isPermaLink="false"

So how can I access the isPermaLink attribute of every feed item to post-process the SimplePie output?

Revent
  • 2,091
  • 2
  • 18
  • 33
The Bndr
  • 13,204
  • 16
  • 68
  • 107
  • 1
    Be careful though... There are cases when the isPermaLink is set to true, but the link is not a link :/ Our experience at [Superfeedr](https://superfeedr.com) is that you should always check the type and validity of the data in a feed! – Julien Genestoux May 14 '14 at 14:36
  • Have you tried [get_item_tags()](http://simplepie.org/wiki/reference/simplepie_item/get_item_tags)? – Revent May 26 '14 at 00:42
  • @revent Yes, I did. Found this some days before. (see my answer) The problem is, that some Feeds mar that link as ` isPermaLink="false"`, even if the link is an valid link. So this is of cause not an simplepie Problem. its more a issue, how does the provider create the rss feed. – The Bndr May 27 '14 at 08:38

1 Answers1

2

On option is to use the get_item_tags method in order to walk trough the array and search for the first isPermaLink:

$guid = $item->get_item_tags('','guid');
$arrIt = new RecursiveIteratorIterator(new RecursiveArrayIterator($guid[0]));
foreach ($arrIt as $sub) {
   $subArray = $arrIt->getSubIterator();
   if (isset($subArray['isPermaLink']) && $subArray['isPermaLink'] == "false") 
       {$isPermalink = false ;break;}
}

This works, but it's not satisfying, bacause some RSS provider sets isPermaLink to false even the link works correctly for a long time.

The Bndr
  • 13,204
  • 16
  • 68
  • 107