Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
One thing that I continually run into when theming sites is the fact that Drupal hardcodes RSS feed links to the bottom of the $content in phpTemplate. This makes it really hard to move around this icon on the page.
This patch creates 2 new functions: one for setting the feed url for a page and another for grabbing it. It then pipes this url into a $feed_icon for phpTemplate, so you can place it anywhere you want in your theme.
Simple and elegant :-)
Comment | File | Size | Author |
---|---|---|---|
#29 | feed_12.patch | 2.68 KB | m3avrck |
#26 | feed_11.patch | 2.69 KB | m3avrck |
#21 | feed_10.patch | 5.55 KB | m3avrck |
#17 | feed_9.patch | 9.02 KB | m3avrck |
#16 | feed_8.patch | 8.93 KB | m3avrck |
Comments
Comment #1
jjeff CreditAttribution: jjeff commentedVery cool!
+1
Comment #2
Dries CreditAttribution: Dries commentedLooks like what other systems would use a template 'tag' for.
Comment #3
drumm- What happens when there are multiple feeds on a page?
- This would be a good opportunity to centralize
<link rel=...rss stuff
.I don't think either of those should hold up this patch since it already seems like a good improvement.
I do have an idea for making the syntax on the template end better (psuedocoe):
Then a simple call to that can be put in page.tpl.php and in the appropriate place in .theme themes.
Comment #4
m3avrck CreditAttribution: m3avrck commentedNeil, I thought about the multiple feeds per page as well but after looking through core, this doesn't seem to apply. Also, I couldn't really think of a situation where multiple feeds would be set on the same page so I opted for the simpler route. If this need does arise, it would be easy later on to alter drupal_set_feed_url() and drupal_get_feed_url() to work with arrays.
Further centralizing link rel stuff would be good too, but that is a bit outside the purpose of this patch, although this patch is the first step in the right direction.
Newly updated patch with the new drupal_feed_icon() to clean up the code a bit. Should be ready to go now.
Comment #5
m3avrck CreditAttribution: m3avrck commentedIt's still ready ;-)
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedIf you modified it to: drupal_set_feed_url($url = NULL, $icon_theme = 'feed_icon')
You could make it store a list of feed_urls with the theme for the icon to use, so that it can print multiple icons. I think it should be trivial.
Views can already make use of something like this, as it can do both RSS and atom feeds on a page, and puts icons (tho at the moment atom.module doesn't actually have a theme_atom_icon and it could probably use one. But nobody's maintaining atom.module, really)
Comment #7
Gábor HojtsyIn case you start adding modules like 'atom' or 'commentrss', you quickly get multiple feeds per page. A comment and a node RSS for example on a taxonomy page, or an atom and an RSS feed. Commentrss module would nicely plug into this feature, if it would allow for more than one feed per page. So it should :)
Comment #8
m3avrck CreditAttribution: m3avrck commentedOk here's an updated patch that allows multiple feeds per page and different feed icons per feed.
I think that's it, ready to go?
Comment #9
Gábor HojtsyLooking at this code fragment:
I thought one of the goals of this patch is to eliminate fiddling with add_link for feed links. The rel=alternate is obvious, the type and title would need to get passed to drupal_set_feed() additionaly. Then if the type is passed on to theme_feed_icon, there would need to be no $icon parameter to drupal_set_feed.
So drupal_set_feed($url, $type, $title) would store an icon (themed through theme_feed_icon with $type passed on) and set a HTML link tag too.
Also $stored_urls does not look good in drupal_set_feed(), since it does not contain URLs, but themes icons (images) actually.
Comment #10
m3avrck CreditAttribution: m3avrck commentedGoba, this patch does not address the drupal_add_link() requests. It just consolidates all of the feed icons and direct links on the page (like on a taxonomy page the little feed icon at the bottom). Neil suggested that too above, but that is outside the scope of this patch.
I agree that should be addressed but in another patch.
Also, the $stored_urls is correct, since that variable is holding an array of URLs/icons. Or maybe "stored_feed_links" would be better.
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedI would say this is RTBC.
Comment #12
drummSince this allows multiple feeds, it should be drupal_add_feed() instead of set and drupal_get_feeds() instead of feed.
The theme_..._icon() construct isn't standard and I'm not sure how useful this will be in real life. I think we should either:
- Accept a whole a $function argument that is the themeable function name.
- Realize that theme_feed_icon() is themeable and let calling it be hard coded.
Comment #13
m3avrck CreditAttribution: m3avrck commentedNew patch that addresses Neil's issues. Now you pass in the full theme function you want to use, this is great because a themer can add a list of theme_atom_feed() etc time functions and just alter each and every icon super easily.
Ready to go now!
Comment #14
m3avrck CreditAttribution: m3avrck commentedUpdated patch for HEAD.
Comment #15
m3avrck CreditAttribution: m3avrck commentedUpdated for HEAD.
Comment #16
m3avrck CreditAttribution: m3avrck commentedOops a little conflict got through, here is a revised one.
Comment #17
m3avrck CreditAttribution: m3avrck commentedUpdated for HEAD. New $delimiter to be more conistent with core, thanks to Earl for that tip.
Comment #18
merlinofchaos CreditAttribution: merlinofchaos commentedThis looks good to go to me; it's gone through quite a lot of hammering to get to this point!
Comment #19
drummCommitted to HEAD.
The RSS autodiscovery link should be added by drupal_add_feed() as the icon is added.
Comment #20
m3avrck CreditAttribution: m3avrck commentedTalking with Neil a bit more, this entails:
drupal_add_link() inside drupal_add_feed() and remove all the separate places we call it now
you would have to add a $title parameter to drupal_add_feed()
Comment #21
m3avrck CreditAttribution: m3avrck commentedConsolidate the drupal_add_link() calls.
Comment #22
m3avrck CreditAttribution: m3avrck commentedComment #23
walkah CreditAttribution: walkah commented+1 this looks good.
Comment #24
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD.
Comment #25
drummThe titles are missing the two feeds in the aggregsator module.
Comment #26
m3avrck CreditAttribution: m3avrck commentedNeil, good catch.
This patch cleans up the aggregator titles, along with the main RSS feed. Additionally, it cleans up the hack in there to add the aggregator feeds; they have been moved to their appropriate functions now for added clarity.
Comment #27
Dries CreditAttribution: Dries commentedPlease double check the use of arg(2) -- make sure it can't be used for XSS attacks. It goes off to various paths (drupal_add_feed, drupal_add_link, etc). They all need to escape arg(2) later on ...
Comment #28
drummAnd t('Drupal') should be simply 'drupal', which seems the most common default for this ('Drupal' is second)
Comment #29
m3avrck CreditAttribution: m3avrck commentedDries, the arg(2) is taken care of. Before that function is called, the menu callback is:
So arg(2) is checked through that function and proper passing to %d in the query. When it gets to that function, it's already a valid %d that was in the database. arg(2) was already being used on the line above and below, no problem.
@drumm - I was following suit with how that was already working in aggregator but you're right. New patch to fix that.
Comment #30
m3avrck CreditAttribution: m3avrck commentedCommitted by Dries. http://drupal.org/cvs?commit=39020
Comment #31
(not verified) CreditAttribution: commented