Community

Customizing the display of Aggregator items, the Drupal Way

I have Aggregator installed on my Drupal 5.1 setup, and have customized the display of aggregator items (rss feed items) by creating a custom display block and theming that block (PHPTemplate). The method I am using does not seem to be the "Drupal Way" though; I am calling db_query_range() to extract a number of rss items directly from the database (aggregator_item table), then iterating through the results and applying customizations. Then I just set any arbitrary item (like 'Syndicate', or 'User Login') to display in that block (to enable it, I guess); my content overrides what was set, and everything "just works". I have to presume that this is not the right way to do it.

The customizations I am performing include
-modifying the 'title' if necessary (some feeds supply the source with the title; I like to separate them in the markup)
-changing the format of the date (from unix timestamp to something readable)
- placing the feed-item fields in the appropriate html markup
- filtering out items from sites that I don't want my customers going to :)

I have read (more like skimmed for what I needed) the new Drupal book, and I have read tons of documentation from this site, but maybe I haven;t absorbed it all. I suspect that there is an official/proper/right way of theming this data, that does not involve overriding a block's set contents; can someone point me in the right direction? I suspect that I'll need to extend the functionality of the Aggregator module in some way; this is not a problem.

Please note that I cannot use simplefeed or feed aggregator b/c they are somewhat broken for 5.1 (I've tried them both already).

Some code (from \themes\\block-rss_column.tpl.php):

<?php
$result
= db_query_range('SELECT title, description, link, author, timestamp FROM {aggregator_item} WHERE fid IN(9,10,11) ORDER BY fid ASC, timestamp DESC, iid DESC', $feed_id, 0, 20);
while (
$item = db_fetch_object($result)) {

   
// Note - if we're using the google news feed, strip off the remaining characters after the first incidence of " - "

   
$rsstext = '';
   
$rsstitle = explode(" - ", $item->title);
   
$rsstext='<div class="story"><h5><a target="_blank" href="' . $item->link . '">' . $rsstitle[0] . '</a></h5><div class="byline">' . $rsstitle[1];
   
$rsstext.='&nbsp<span class="timestamp">' . date("F j, Y", $item->timestamp) .'</span></div>';
    if (
$item->description != '') {
   
$rsstext .= '<p class="summary">' . teaser($item->description) . '</p>';
    }
   
$rsstext.='</div>';
    print
$rsstext; //theme('item_list', $items);
}

function
teaser($rss_description) {
   
$sentences = explode (".", $rss_descriptions);
   
$retsenc = '';
    for (
$i=0;$i<2;$i++) {   
   
$retsenc.=$sentences[$i].'...';   
    }   
    return
$retsenc;   
}
?>
nobody click here