Displaying RSS feeds on the fly in alayham.net

alayham's picture

I wanted to display RSS feeds on this site, and wanted to be able to display just the links, without storing the feed in my DB or being able to show the the description or the content. I checked the available RSS modules for drupal, but did not find any module that can do what I need. After all, I found that my experience with Drupal feed readers is worth sharing as my first article in my site.

The core aggregator module displays automatic blocks with links, but it stores items in a flat table making them searchable, I could live with that, but after some testing, I discovered it fails with a mysterious "http request status fails" error on some feeds. Drupal team acknowledged the issue, and there is a module that tried to reset the flag. I tried it, and it did not work, possibly because Drupal really could not consume blogger feeds on my server. So the core aggregator module is not what I need.

The other aggregator modules, including FeedApi, will not only store the items in my DB, they will create them as nodes, and this is what I really hate. I can not imagine why I have to store partial content and links from other sites as content items in my site.

After hours of testing all the modules, I concluded that if I really want what I want, I have to do some coding. Two years ago, that would be fine. but today, the problem is that I have not written any php line since 2006. I don't have the Dev platform at my work laptop.

While experimenting with SimplePie I watched a small tutorial video, and I liked it. SimplePie can download and parse the feed on the fly, and it can expose the feed items as an array so that I can display the number of links i want in a simple loop, SimplePie can also cache the downloaded feeds, and it can merge multiple feeds and sort them by time. this is AWESOME.

Drupal has a SimplePie core module that integrates and exposed SimplePie to the Drupal framework. I installed it on the live server, and configured the cache folder, then started thinking about how to display the feed items as links. I should have a place to store the feed links, and I want to display the feed items in blocks on the right column. the easiest way to do this is to enable the PHP filter, and put the code in the block itself

I tested the idea using my Bahrain Jobs feed that I generate on Yahoo! Pipes. And it worked. so I added another block to display some joint feeds from selected Bahrain Blogs. This is really what I wanted.

<ul>
<?php
    $max
=10;
   
$url[]='http://pipes.yahoo.com/pipes/pipe.run?_id=eGsnCafE3RG5CGyJ_w6H4A&_render=rss';
   
$feed=simplepie_get($url);
    for(
$x=0;$x<$max;$x++){
       
$item=$feed->get_item($x);
        echo
'<li><a target="_blank" href="' . $item->get_permalink() . '">' . $item->get_title() . '</a></li>';
    }
?>

</ul>

Writing PHP code in the block body is not the best way to display feeds, the proper procedure is to write a module that can take multiple feeds and generate blocks (and possible Pages) to display feed items. another simple idea is to write an input filter that can transform feed links in the block body to a list of item links. I will not do that in the near future, but if I can get hold of a Dev environment, I certainly have an Drupal module idea.

Comments

alayham's picture

Update

I Published this article in the drupal forum

====
Al-Ayham Saleh