Redirecting Radio UserLand URLs with PHP

This weblog uses Python Community Server (PyCS), an open-source version of the Radio Community Server, to host visitor comments and trackback links. It's a reliable service that adds a few new features beyond the ones offered by UserLand's comment server: Comment deletion, RSS feeds for every discussion, and the ability to download all of your comments as a single file in RSS 2.0 format.

If you inspect the comment and trackback links on this site, you'll see that they appear to be hosted here on rather than on

I'm doing this with two simple PHP scripts that redirect the URLs to the correct PyCS URLs.

I implemented this feature so that I can take comment and trackback links offline when PyCS experiences an outage.

During a comment/trackback server outage, Workbench (and presumably most Radio weblogs) won't display a weblog page until the server request times out with an error -- a delay of 60 seconds or more. Most visitors conclude the site itself is offline and give up, causing traffic to slow to a trickle.

Now during an outage, I can replace the redirection scripts with "comments offline" and "trackbacks offline" text.

Here's the PHP script to redirect comments:

$url = str_replace("128729", "0000001", $REQUEST_URI);
$url = str_replace("/workbench/php/comments.php", "/system/", $url);
header("Location:".$url); exit;

This script does three things to the requested URL, which PHP makes available in a $REQUEST_URI variable:

  1. Change my Radio user number (128729) to my PyCS user number (0000001).
  2. Change my redirection URL on, /workbench/php/comments.php, to the real URL on PyCS, /system/
  3. Redirect the browser to the real URL on PyCS.

For example: Here are links to an original URL and a redirected URL.

The same technique is used in a trackback redirection PHP script:

$url = str_replace("128729", "0000001", $REQUEST_URI);
$url = str_replace("/workbench/php/trackback.php", "/system/", $url);

The scripts are stored in a php folder inside Radio's www folder. When there's an outage, I move the scripts and create new versions of the files with nothing but text like this:

Comments offline

There's probably a way to accomplish this in Apache with .htaccess files and mod_rewrite, but PHP made it too easy to look elsewhere.

Displaying XML Data on a Radio UserLand Weblog

Peter Backx has created a UserTalk script that displays random pictures on the homepage of his Radio UserLand weblog.

The script's a nice, straightforward example of how to use UserTalk to read XML data from a file and do something with it.

I have modified his script to create a random text link that can be displayed on any Radio Web page. The link will be updated each time the page is republished, displaying a different link from an XML file called randomtextlinks.xml

Here's the script:

on randomTextLink() {
  «5/11/03; 11:08:43 AM by Rogers Cadenhead     «     «Based on the randomLink script by Peter Backx       «     «Modified to support text links instead of pictures   local (s = "", pc = file.getPathChar ());   local (f = + pc + "gems" + pc + "randomtextlinks.xml");   local (table);   xml.compile (file.readWholeFile (f), @table);   local (adrlinks=xml.getAddress(@table, "links"));   local (ltable=xml.getAddressList(adrlinks, "item"));   local (i = random(1,sizeof(ltable)));   local (name = xml.getAttributeValue(ltable[i],"name"));   local (url = xml.getAttributeValue(ltable[i],"pagename"));   s=""+name+"";   return s; }

To use the script:

  • Download the file workspace.randomTextLink.ftsc.
  • Open the Radio application (in Windows, right-click Radio in the System tray and choose Open Radio).
  • In Radio, choose the menu command File, Open, then find and open the file you just downloaded.
  • Radio asks if the file should be imported as workspace.randomTextLink. Click OK.
  • In your /www/gems folder, create an XML file called randomtextlinks.xml that contains a URL and text for one or more links (or use mine).

After the script has been installed and the XML file has been created, you can put the text <%workspace.randomTextLink()%> on any Web page or page template to call the macro, which displays a randomly selected link.

Adding a Date Countdown to a Radio Weblog

On the West Highland Way weblog, James McReady is counting down the days until a sponsored charity walk is talking place.

Right now, he's providing the countdown manually by editing the text himself.

I wrote a short UserTalk script that can count down to any specified date in the future:

To use it:

  1. Save the file workspace.daysUntilEvent.ftsc to a temporary location on your computer.

  2. Open the Radio application.

  3. Use File, Open to find and open workspace.daysUntilEvent.ftsc. A dialog box appears asking for the name to give the imported object.

  4. Accept the default, workspace.daysUntilEvent.ftsc, and click OK. If you already have a copy of this script (or another script with the same name), you'll be asked if it should be replaced.

Once the script has been installed at workspace.daysUntilEvent, you can call it on any page of your Radio weblog. It takes the following arguments, in this order:
  1. target Day of Month

  2. target Month

  3. target Year

  4. target Hour (optional)

  5. target Minute (optional)

  6. target Second (optional)

The optional arguments all default to zero, causing the countdown to use midnight as the time if no hour, minute, or second are specified.

Here's a countdown to Christmas:

<% workspace.daysUntilEvent(25, 12, 2003) %>

As of the last time this page was published, there are [Macro error: Can't call the script because the name "daysUntilEvent" hasn't been defined.] days until Christmas 2003.

Here's a countdown to Millard Fillmore's 204th birthday:

<% workspace.daysUntilEvent(7, 1, 2004) %>

There are [Macro error: Can't call the script because the name "daysUntilEvent" hasn't been defined.] days until Fillmore's birthday.

Radio only runs a macro on a page when the page has been updated. If you're putting the countdown clock on your weblog's home page, you can make it publish automatically once a day using the scheduler.addTask verb:

  1. Open Radio.

  2. Choose Tools, Developers, Quick Script. The Quick Script window opens.

  3. Enter scheduler.addTask (, "radio.weblog.publish()", 1440) and click Run. The page will be published once a day at the same time you ran the script.

The verb returns a value representing the current second. You can use a different value for the first argument to cause the page to be published earlier or later in the day. Just add the number of seconds until it should first be run -- for example, scheduler.addTask( + 79200, "radio.weblog.publish()", 1440) runs it 22 hours in the future, then every 24 hours after that.

Publishing Files to a Second Server with Radio UserLand

Scott Johnson is running out of space on Radio UserLand's server, which creates a dilemma because UserLand doesn't offer a way to buy additional space. Once the 20MB limit is reached, most users delete files or move to another server.

Another way to save space on your weblog: Set up Radio to publish some of your files to a second server. If you have an FTP account on another server, it's easy to publish a folder to that server.

The steps:

1. Create a new folder in your /Radio Userland/www folder. I called mine offsite.

2. Create a new password for your FTP account. Don't put your FTP username in the Password Name field. Instead, give it a descriptive name such as the name of your FTP provider. I called mine BellSouth.

3. Create a file called #upstream.xml that takes this form:

<?xml version="1.0"?>
<upstream type="ftp" version="1.0">

Change the values in this file to match those required by your FTP server: username (FTP username), server (FTP server), path (folder on the FTP server), url (Web address of that folder), and passwordName (the descriptive name from Step 2). Don't put your FTP password in this file.

4. Save #upstream.xml in the new folder.

5. Try it out -- save something in the folder such as this Microsoft Bob mug:

If the FTP settings are correct, the file will show up automatically in the new server, which you can check in Radio's Events Log. Anything else you save in the folder will be upstreamed to the server (except for files beginning with a "#" character).

Radio supports multi-server publishing with FTP, XML-RPC, and SOAP. More information is available in the #upstream.xml specification.

Radio Userland Format Driver for NASA News

I have written a Radio Userland format driver to read news from NASA, which is offered as an XML feed. Because this feed is not in RSS format, you must install a special format driver to read it with Radio Userland's News Aggregator. 

To add the driver to Radio Userland:

  1. Download formatDrivers.newsfeed.fttb and save it to a folder on your system.
  2. Open Radio Userland (in Windows, right-click the RU icon in the System tray and choose Open Radio).
  3. Choose File, Open and open formatDrivers.newsfeed.fttb.
  4. You will be asked if you want to save the file as user.xml.rss.formatDrivers.newsfeed. Click OK.
  5. If you already have this format driver, you will be asked if you want to replace the existing newsfeed table. Click No.

After the script has been added, open the News aggregator page and add the NASA XML feed as if it was an RSS channel.


  • 3/17/02: Released driver, which is based on an original script by Dave Babbitt.

    Publishing a Category to a Private Location

    Brett Morgan wants to publish a Radio Userland category to a private "behind-the-firewall" location. If you can upload to the location using FTP, you can accomplish this by creating the new category, adding your FTP password to Radio Userland, and putting an #upstream.xml file in the category's folder that contains your FTP settings.

    For example:

    1. Create a new category. I called mine Private.
    2. Choose the "render this category in HTML" option and do not choose the "notify Weblogs.Com" option.
    3. Choose a theme for the category's HTML rendering and submit the category.
    4. Create a new password.
    5. Give the password a name that describes its role. I gave mine the same name as my FTP username, but that's not required.
    6. Enter your FTP password and submit the password.
    7. Open the folder that contains your category, which is named after the category. Because I named mine Private, it is in Radio Userland's www/categories/private folder.
    8. Create a file called #upstream.xml in that folder and add your FTP settings to it.
    9. The #upstream.xml file must contain your FTP server name, username, the folder that will contain your category and its URL.
    10. Don't put your FTP password in the passwordName element of this file. Instead, put the name you gave the password in Step 5. Here's the #upstream.xml I created (the name was changed so I could publish it; Radio Userland won't normally publish files that begin with a "#" sign).
    11. Publish an item to your private category.

    Important note: None of this makes your category private. You must make sure the FTP location is private on your own.

    I published my category to a folder that uses Apache's .htaccess feature to keep people out. As far as I can tell, it's working. If anyone can figure out a way to view what I have said about the musical group Creed in my private weblog, let me know and I'll update this story.

    Posting a Category as a Salon Blog

    Disclaimer: I have only tried this once, so I can't vouch for it's reliability in all situations. I'm offering these notes as a guide for people who are comfortable with Radio Userland and the Radio.root database.

    It's possible to publish a Salon Blog as a category of your existing Radio Userland weblog, but it's a pretty messy process.

    I publish the Workbench weblog on one community server and paid for a Salon Blog earlier this week. I'd like to publish both using a single copy of Radio.

    Though I think it might be more trouble than it's worth, here's how I set it up, thanks to some tips from people on the Radio Userland support forum:

    1. Close any copy of Radio Userland that is currently running.
    2. Backup everything in the Radio folder (probably Program FilesRadio Userland on Windows). You need an extra copy of all your existing data, so you have something to fall back if you can't get this to work.
    3. If you haven't done this already, download and install the Salon version of Radio Userland. Make sure to install it in its own folder. I installed mine in Program FilesRadio Userland Salon.
    4. Open the folder where you installed the Salon version of Radio and run the program.
    5. If you have customized any of the templates used on your Salon Blog, create a theme containing your site's design. Give it a descriptive name such as the name of your Salon weblog. This theme will be stored in a single file in the Themes subfolder (mine was in Program FilesRadio Userland SalonThemes).
    6. Open Radio so you can view its database. Choose Window, Radio.root and expand the item Write down the value of this item, which will be a sequence of 18-20 letters and numbers.
    7. Quit the Salon version of Radio.
    8. Copy the theme file you just created to the Themes folder of your original Radio installation.
    9. Start your original version of Radio.
    10. Create a new category that will hold posts to your Salon Blog. Give it the same name and description as your Salon Blog.
    11. Open the www folder of your Salon version of Radio (mine is in Program FilesRadio Userlandwww) and copy the #upstream.xml file.
    12. Open the wwwcategories folder of your original version of Radio, then open the folder named after your new Salon category.
    13. Paste the file #upstream.xml into the new Salon category folder.
    14. Open the file #upstream.xml in the new Salon category folder with a text editor and look at the line that has the XML tags <password> and </password>. The word "default" is probably displayed between these two tags.
    15. Replace the word "default" with the word "salon" (without the quotes).
    16. Open Radio so you can view its database. Choose Window, Radio.root and select the item
    17. Hit CTRL-C to copy this item.
    18. Hit CTRL-V to paste it. You'll be asked if you want to Replace the existing item, Duplicate the item, or Cancel.
    19. Click the Duplicate button. A new item will be created called default #1.
    20. Click your cursor on this item, then use your keyboard to give it the new name salon.
    21. Change the value of this item to the password you wrote down in step 6.
    22. Open the main Radio interface and click the name of your new Salon category.
    23. Check the box to render the category in HTML.
    24. Change the Theme of the category to the theme you saved from your Salon Blog in step 6.

    At this point, anything you post to the new Salon category will show up on your Salon weblog, instead of your main Radio Userland weblog. Your Salon weblog will use the main weblog's navigator links, referrer link, and updates link. Also, if you use comments, the Salon weblog will use the same commenting system as your main weblog, rather than the one on Salon's community server.

    Posting to Radio Userland from Different Places

    A visitor to Workbench asked how you can post to a Salon Blog from Radio Userland on several different computers. There isn't an easy way to do this, unless you have an always-on Internet connection and can keep Radio running on it.

    When you post an item, Radio saves it on your computer in a database file called weblogData.root in the software's Data Files folder. Any time your weblog is published, Radio reads data from this database, produces HTML files from it, then uploads those HTML files to the Salon Blogs community server. If you set up Radio on two different computers, they will have different weblogData.root files.

    I don't have an always-on Internet connection. If I wanted to post from different computers with Radio, I would run the software from a folder on some kind of portable storage device, such as a ZIP disk, USB microdrive, or the like.

    If you can stay connected to the Internet, there are two ways to post to a Radio weblog from multiple PCs.

    Posting Remotely to Radio Userland Using E-mail

    Turn on the Mail-to-Weblog feature. Radio can read an e-mail account and post everything sent to it with a specific subject line. All other mail will be ignored, so it should be an e-mail account you're not using for any other purpose.

    This feature only reads mail while Radio is running and connected to the Internet. If you shut down Radio and go on a trip, any weblog entries you e-mail while traveling won't be posted until you run the software again.

    Connecting to Radio Userland Remotely

    If the Remote Access and Security feature is turned on and set up with a username and password, you can connect to the computer running Radio over the Internet and use its browser interface to work on your weblog.

    You must know the IP address or host name of the computer. To load Radio remotely, type this address in a Web browser's Address bar followed by the port number 5335. For example, if I was running Radio on, I would connect to

    Phillip Pearson describes both of these options in more detail on his Salon blog.

    Moving Outline Items in Radio Userland

    Radio Userland tip: Items in an outline are moved using drag and drop. When you're moving an item, you don't have to grab it by the item's triangle, which is small enough that it's a challenge for fumble-fingered users like me.

    An easier way to grab the item: Click any empty spot to the right or left of it.

    To show this, I've added yellow boxes to the outline below. If you wanted to move Item 1a, you could click anywhere in those yellow areas (which aren't visible in Radio Userland) and hold your mouse down, dragging the item to a new location.

    Outline window

    I found this tip in Matt Neuberg's book Frontier: The Definitive Guide, which is available for free online. Though it documents Frontier 4.2.3 for the Macintosh, the book can be useful for Radio Userland users who want to learn how to write scripts and make use of the Radio Userland interface and database, because Radio Userland shares so much in common with Frontier.

    Radio Userland Access Control

    Radio Userland doesn't offer access control at the present time, so your weblog's open to the public from the moment you set it up.

    Using Javascript and a custom User-Agent string on my browser, I devised a workaround that let me view my weblog but sent other people somewhere else. It uses Windows and Internet Explorer 6, but the technique can be adapted to any browser where you can set the User-Agent string. It only keeps out people who have Javascript turned on in their browser (more than 90 percent of all web users, by my guess).

    Step 1: Change Your User-Agent String

    First, modify the User-Agent string in Internet Explorer. The User-Agent string is sent to a server when you request a page, and it identifies your browser, browser version, and often other things about your system.

    Here's my current User-Agent string for Internet Explorer 6 on Windows XP:

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; .NET CLR 1.0.3705)

    You can see your browser's User-Agent string on this IP Delivery browser variable page.

    The User-Agent string contains several tokens in parenthesis separated by semi-colons. You can add a token of your own by adding an item to the Windows Registry. (Standard disclaimer: Be careful when editing your registry. It's a great way to hose your system if you're not sure what you are doing.)

    Run the Registry Editor and open the folder My Computer, HKEY_LOCAL_MACHINE, SOFTWARE, Microsoft, Windows, CurrentVersion, InternetSettings, User Agent, Post Platform.

    Add a new item: Choose Edit, New, String Value. An item will appear in the Post Platform folder with the type REG_SZ and the name New Value #1. Give it a new name that isn't likely to appear in someone's User-Agent string -- Foobar, Swordfish, Heffalump, Woozle, or the like.

    Exit the Registry, shut down Internet Explorer, and open it back up. Your User-Agent will have the new token in it. When I added Swordfish to mine, it became this:

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; Swordfish; .NET CLR 1.0.3705)

    Step 2: Add a Script to Your Weblog

    After you have modified your User-Agent string, add a script to the HTML templates of your weblog to look at that string and send people to a different page if their User-Agent doesn't contain the token.

    If you know how to change your templates and republish the weblog, add a script like this to the top of each page that should not be open to the public, right after the <body> tag:

    if (navigator.appVersion != "4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; Swordfish; .NET CLR 1.0.3705)" {

    This script requires two changes:

    First, modify the text in the if statement so that it includes everything in your User-Agent after the first "/" character.

    Next, set the variable top.location to the URL where people should be sent if they don't have the right User-Agent string. I sent people to the Radio Userland home page.

    Save the template and republish the pages in your weblog that use the template.

    This technique keeps most people out and discourages anyone from linking to your weblog while it's under development. Because it's easily circumvented by turning off Javascript, it isn't a substitute for normal access control.

    Radio Userland Format Driver for Amazon XML Feeds

    I have written a Radio Userland format driver to read Amazon's XML feed of best-selling products for any category and keyword you designate (example; requires Internet Explorer 5 or 6 to view in a browser).

    To add the driver to Radio Userland:

    1. Update Radio.root.
    2. Download formatDrivers.catalog.fttb and save it to a folder on your system.
    3. Open Radio Userland (in Windows, right-click the RU icon in the System tray and choose Open Radio).
    4. Choose File, Open and open formatDrivers.catalog.fttb.
    5. You will be asked if you want to save the file as user.xml.rss.formatDrivers.catalog. Click OK.

    After the script has been added, open the News aggregator page and add an Amazon XML feed. Feel free to modify my example -- change "naviseek" to your Amazon Associates ID, change "books" if you want a different category (such as "software") and change "Rogers%20Cadenhead" to the keyword you want to search for, replacing all spaces with %20 as I did).