Adding a link to the feed source in Aggregator blocks
I'm trying to modify the Aggregator block output slightly, so that alongside the item title and link, it has the feed title and a link to the feed as well.
The line that I am trying to edit to put this in is:
$output .= '<a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a>\n";
I have been trying various different variables that are used in different parts of the module to add in the feed source and title but I don't seem to be getting anywhere.
I think it should be something like
$output .= '<a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a>\n".', <a href="'. check_url($feed->link) .'">'. check_plain($feed->feed_description) .';</a>'
But that doesn't seem to work, nor does any of the other combinations I have tried.
Any help would be greatly appreciated!
Thanks.

Couple things
First of all check the l() function to create links. Then take a look at the Simplepie module. Also check my just uploaded module 'SimpleBlogroll' (http://drupal.org/project/simpleblogroll) which you might find interesting (code through CVS repository until project page is updated).
I have been having a look
I have been having a look through those modules and at the l() function, though still have not had much luck. As far as I can tell, the simplest way should be to take the variables that are used in the .tpl.php files, particularly aggregator-summary-item.tpl.php that appear to be assigned in the aggregator.pages.inc file.
However, these variables aren't available in aggregator.module so I'm wondering if alternatively, there is a way to use the contents of aggregator/categories/ and place that within a block instead, basically the output of aggregator-summary-items.tpl.php. Then removing the date from the aggregator-summary-item.tpl.php.
Another possibility could be to run the php needed for it through a block. I'm not sure how to go about doing this though, the variables aren't picked up in the block so I assume it needs to be told where to find them?
I haven't really looked into
I haven't really looked into tpl files deep enough to give you a hand on that aspect. But on the other hand, I just reread your initial post and I'm now absolutely convinced my module covers just what you seek: A block, with feed titles (and link to feed) followed by the latest item and its link (and optionally the tag 'new' if the item is recent). All links link to the external sites and no nodes are created.
For just modifying the output through theming,
I'm not that's the name of the variables to call (don't know if they are even available outside of the aggregator functions)(EDIT: never mind, looks like I didn't pay attention). Theming usually gets me confused... Why don't you making a new module? Also, have you tried views?Your module is close to what
Your module is close to what I'm after, but not quite. I would like to keep the feed aggregation the way it is at the moment with the created nodes, and with the block displaying the latest items in a particular category. However, I would like to add a link back to the original site as well as the link to the original blog post within this block.
So for example, if there are 5 blogs being aggregated and the I'm showing the 10 most recent blogs in that block, 3 of them might be from the same blog and so I would like them to all show up rather then just the latest one from each blog like yours shows - I may have missed something though, can your module do this?
Views unfortunately don't seem to give the control I need over the aggregated items.
I don't think a new module is really necessary, I think I should just be able to add in the feed title and feed url variables to the block output along with the current item title and item url. I don't seem to be able to get this to work though.
EDIT: I believe it should go into this section of the module: http://api.drupal.org/api/function/theme_aggregator_block_item/6
Definitely on my module's TODO list
Believe me, before making the module I did try other alternatives and ended up where I am.
Being able to select the amount of feeds to display from each feed was clearly the next step in my module's TODO list (I have all my code prepared for it already). However, your idea of directly ordering item chronology instead of feed chronology seams much smarter.
Question: what did you plan to do if the 1st and 3rd latest items (say, items 'A' and 'B') were from the same feed '1' and the second latest ('C') from feed '2'? Would you have the block show the feed '1' with its item 'A', then feed '2' with its item 'C' and then feed '1' again with its item 'B'?
So:
Feed '1'
-->item 'A'
Feed '2'
-->item 'C'
Feed '1' (again)
-->item 'B'
It would seem very tedious to make an algorithm to detect if the parent of the item (in this example, item 'B', parent: feed '1') has already been printed and group it together (if it is on the 10 latest list). And it wouldn't make the sorting accurate either, because item 'B' wasn't published before item 'C'.
If you want me to, I can add the functionality to my module (please specify first though), since it does not vary too much from what I was planning to do anyways.
That's about what I was
That's about what I was aiming for yeah.
The functionality to order them in that way is already in the aggregator module which is why I was hoping I could just add a little bit of extra code to the output to add the feed title and URL into it.
Ideally I would like to print them more like:
Item 'A', Feed '1'
Item 'C', Feed '2'
Item 'B', Feed '3'
Basically so rather then it being a list of feeds, it's a list of blog items with their source. This formatting could probably be adjusted easy enough in your module by re-arranging the output a bit in _simpleblogroll_build_block().
What do you think? If you can add that sort of functionality to your module, that would be great. I should be able to adjust the formatting of the output myself for what I need.
Like I said though, the aggregator module already does the ordering the way I want it, I just haven't been able to get it to add the feed title and URL. I'm probably just missing something really simple, but it's got me pretty stumped at the moment. So adding this sort of functionality to your module may be starting to overlap or double up on the aggregator module?
There might be an overlap,
There might be an overlap, yes. But I've had big problems with a lot of feeds with aggregator in the past, and also code hacking (aka customizing with templates) makes features unavailable for non developers. That's why making this functionality available through a module is essential.
Here are my thoughts for making this happen. (Lets say displaying is set to 10 elements).
Admin section:
Code (for each feed):
What do you think?
That sounds pretty much
That sounds pretty much perfect!
The HTML output wouldn't necessarily need to print them underneath each feed title though, at the moment, you have used line breaks to position them below each other. However, if they were placed in 's with a class say class="feed-url" or placed in a list, then by default they should be positioned below each other, but it also gives the user a little bit of extra control to theme them with CSS without having to even look at the source of the module or change what it is outputting.
Perhaps something like:
<ul class="simpleblogroll"><li>
<ul>
<li class="feed-item"><a href="itemA-url">Item A Title</a></li>
<li class="feed-source"><a href="feedA-url">Feed A Title</a></li>
</ul>
</li>
<li>
<ul>
<li class="feed-item"><a href="itemB-url">Item B Title</a></li>
<li class="feed-source"><a href="feedA-url">Feed A Title</a></li>
</ul>
</li>
</ul>
It could potentially also be done with a single level list and putting a span around the item and then another span around the feed. That wouldn't put them on separate lines by default though.
Using the lists above, it would be easy enough to display them inline or on separate lines with CSS. Span's though would allow the CSS to control whether or not the feed or the item is displayed first. Either option just gives a bit more flexibility then the current HTML output.
I'll be working on it all
I'll be working on it all the afternoon (GMT+1 DST). I'll report back if I run into anything. You're welcome to help if you have anything (regarding the code changes in simpleblogroll).
Almost 3am and I'm stuck
Almost 3am and I'm stuck on AHAH. I've been going through all main drupal IRC channels without finding anyone who seemed to have an idea. I guess I'll have to work around AHAH for now...
Perhaps something from the
Perhaps something from the aggregator module will help?
This section looks to me like the ordering may be part of how the feeds are saved: http://api.drupal.org/api/function/aggregator_parse_feed/6
The other sections are all listed here, I think the above is where the ordering is done, but I'm not entirely sure: http://api.drupal.org/api/file/modules/aggregator/aggregator.module
EDIT: This may have something to do with it as well: http://api.drupal.org/api/function/aggregator_save_item/6
Thanks. Yes it seems
Thanks. Yes it seems aggregator does the ordering at store time. But in this case I'm not sure that's possible, because if the user wants to order by feed, show more than one item of each feed at once, ordering is not chronologically any more. The ordering in this case should rely on db fetching. The choice given to the user makes the code more complex...
Sorry, been snowed under the
Sorry, been snowed under the past couple days.
Thats true. I can see how it should be done, I'm not sure how to go about it in the db fetching though, unfortunately my SQL isn't that good. I'll have a think about it and see what I can come up with, though you may beat me to it.
I've been working on it and
I've been working on it and have the code ready and am now working on some serious debugging. Some conditionals don't seem to work and I can't figure out why. The result is that there is a problem adding feeds. But I'm still working on it... :D The code is now at roughly 750 lines.
It's sounding pretty
It's sounding pretty interesting, I think I'm gonna have to go through it when you have it working and see how it's all done :) Thanks for all your help with this as well by the way.
You bet. I'm undergoing a
You bet. I'm undergoing a heavy exam period this upcoming week, so I'm probably not going to get much done until next weekend. I hope to get everything working by the week after, though.
Good luck with your exams
Good luck with your exams mate!