I want to truncate aggregated content to a few lines per entry. I have had a quick look at the source of the Aggregator module but don't quite know where to start.

I was hoping that I could find the bit where the content gets written out and simply insert a command to truncate the post's body element.

I'd be very grateful if someone could advise whether this is a good strategy and help point me to the right place.

Comments

David McCraw’s picture

It depends very much on how neat you'd like things to be.

As a minimum dirty fix, you can go into the aggregator source, to function aggregator_save_item($edit) .

There you will find the raw queries and be able to impose the necessary restrictions. The element you're interested in is $edit['description'].

A primitive, but functional possibility is to replace $edit['description'] with substr($edit['description'],0,100).'...' This will truncate descriptions at 100 characters with an ellipsis suffix, which looks passable.

More elegant would be to reuse the preg from earlier in the module (which derives a title from the description):

preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 100)).'...';

will give you approximately the same effect, but should end on word boundaries.

playdreamer’s picture

Thanks. I tried the more elegant solution but ran into some problems that were not immediately obvious to me so reverted to the quick and dirty method which works fine for me.

Only one thing to add. I ended up inserting a strip_tags function as the truncation was sometimes happening between tag pairs resulting in the rest of a page being rendered bold, for example. So I ended up with:

substr(strip_tags($edit['description']),0,100).'...'