Hacking Radio's radio.macros.blogroll

I've been using the radio.macros.blogroll macro in my templates to display my blogroll links for some time. One thing that I wanted to do was to have my RSS subscriptions in the middle of my blogroll but not have to use separate blogroll OPML files and multiple macro calls in my template.

At the time I set up my blogroll, I didn't see any other way to do it, so I created my links manually without any subscription info. The macro thus did not display the tiny coffee cup and XML icons next to each link I subscribed to.

Another problem I didn't see a way around was that even if I did use the mySubscriptions.opml file in my blogroll, it looked to be an all-or-nothing deal. All of the links in mySubscriptions.opml are displayed, whether you want them all displayed or not.

Last night, the light bulb went off in my head. Copy only the subscription links I want to display from mySubscriptions.opml to blogroll.opml. Right click on the subscription link in mySubscriptions.opml, click "Copy", switch to the blogroll.opml window, right click on the location where the subscription link should be inserted, then click "Paste". Too easy!

If I decide to unsubscribe from a web site, I just delete the subscription link in blogroll.opml. If I add a new subscription and want to display it on my blogroll, I would just copy the new subscription link from mySubscriptions.opml (which Radio maintains automatically if it is set to do so in the Preferences) and paste it into blogroll.opml.

Today, I was checking over my weblog in both Internet Explorer and Mozilla Firebird and noticed two things I thought should be fixed:

1. The little coffee cup and XML icons displayed by radio.macros.blogroll () are not local. The macro uses these links for the icons:
* http://static.userland.com/shortcuts/images/misc/miniXmlCoffeeMug.gif
* http://static.userland.com/shortcuts/images/misc/miniXmlButton.gif

2. The tooltips for the little coffee cup icons and XML icons were displaying only the file name in Internet Explorer. Mozilla Firebird displays the correct tooltip when my "Popup ALT attribute" extension is disabled; otherwise, it displays only the file name just like Internet Explorer does.

Note: The correct tooltip for the little coffee cup icon should be 'Click to subscribe to "Site Name" in Radio UserLand.' The correct tooltip for the little XML icon should be 'Click to view the XML source for "Site Name".'

The links output by radio.macros.blogroll are actually built by html.data.standardMacros.opmlToBlogroll. I hacked the opmlToBlogroll code as follows:

1. Moved the bundle //set miniMugIcon and miniXmlButton code (3 lines including the bundle statement) from the main line code to the inside of the on addItem () subroutine, so that different tootips can be created for each link as each link is processed. I inserted the bundle just after (and inside of) the if xmlurl != "" /\/get coffee mug and xml button links statement.

2. Used a call to radio.macros.imageRef to get the local icons, instead of the link that was hard-coded into the macro.

Note: In order for this to work, it is necessary to download and save a local copy of the mini-icons. I saved mine to my /www/images directory. It would appear that Radio does not ship with these icons; I could not locate a copy anywhere within my Radio Userland directories.

3. Copied the Title attribute text assigned to the <a href> tags (the two statements now following the bundle code I inserted) and used that as the ALT attribute text in my radio.macros.imageRef call. Without an ALT parameter, radio.macros.imageRef will generate an IMG tag with an empty ALT attribute (alt=""), and this will prevent Internet Explorer from displaying any tooltip at all.

This is what the modified code looked like after I made my changes:

on addItem (text, url, xmlurl, isRecent, target="", tooltip="")
   local (xmllinks = "", targetstring = "", titlestring = "", prefix = "", 
      suffix = "")
   if xmlurl != "" /\/get coffee mug and xml button links
      bundle /\/set miniMugIcon and miniXmlButton
         miniXmlButton = radio.macros.imageRef ("/images/miniXmlButton.gif", 
            align:"middle", alt:"Click to view the XML source for &quot;" + 
            string.replaceAll (text, "\"", "&quot;") + "&quot;.")
         miniMugIcon = radio.macros.imageRef ("/images/miniXmlCoffeeMug.gif", 
            align:"middle", alt:"Click to subscribe to &quot;" + 
            string.replaceAll (text, "\"", "&quot;") + "&quot; in Radio UserLand.")
      xmllinks = "<a href=\"http:/\/127.0.0.1:5335/system/pages/subscriptions?url=" 
         + string.urlEncode (xmlurl) + "\" title=\"Click to subscribe to &quot;" 
         + string.replaceAll (text, "\"", "&quot;") + "&quot; in Radio UserLand.\">" 
         + miniMugIcon + "</a> "
      xmllinks = xmllinks + "<a href=\"" + xmlurl + "\" title=\"Click to view the 
         XML source for &quot;" + string.replaceAll (text, "\"", "&quot;") + 
         "&quot;.\">" + miniXmlButton + "</a> "

If Radio Userland comes through on my request to enhance radio.macros.imageRef so that it will support use of the Title attribute, this code should be changed so that imageRef macro calls use the Title attribute for the tooltip text instead of the ALT attribute. Until then, this hack works for both Internet Explorer and Mozilla Firebird.