Undercrank

Icon

Yahoo! Web Services news over Atom

Well, like a dork, I didn’t actually realise that Yahoo! News already offered up the whole RSS feeds for news keywords thing when I started. However, the fun thing of course with the API that Yahoo! are offering is that it doesn’t take a whole lot of time to create another script that dishes out the same thing in another ‘rival’ syndication format:

Atom enabled Yahoo! web feeds examples

The syntax of the URL is almost identical to that of the RSS feed http://undercrank.com/yahoo/atom/news/«keywords» (the equivalent RSS version would be http://undercrank.com/yahoo/rss/news/«keywords». This is a slight change to the previous syntax posted, but the old format is still perfectly valid and won’t break for those already using it.

As before, the feed validates nicely has good friendly HTTP caching facilities built in, as as a special bonus it conforms to the Tag URI recommendations pretty well too.

Use is made of the extended Author tags for each article, and support for multiple languages for each entry is available – although it appears that Yahoo! returns “en” as the language for everything, even, if it’s not.

Finally, I’ll post up the source once I’m convinced I’m doing everything the ‘right’ way.

Yahoo! Web Services news over RSS

Excited by the prospect of a reasonably usable search API being made available by Yahoo!, I’ve put together a small project that will create an dynamic RSS 2.0 feed based on the Yahoo! News Search hooks.

The feed validates nicely, and also deals well with the tests created by Unpolluted; it has GZip handling, HTTP Expires, Last-Modified, ETag and If-None-Match support built-in.

The usage is very simple – point your aggregator of choice at http://undercrank.com/yahoo/rss/news/KEYWORD, replacing KEYWORD with your appropriate search term. Some examples are given below:

I’ll release the source when I’ve tidied it up a bit so you can host it on your own boxes, but feel free to try it here for the time being.

ALA’s PHP Switcher revisited

Recently, the webzine A List Apart published an article by Chris Clark that demonstrated stylesheet switching using PHP.

The technique works all fine and dandy unless you’re using a more recent installation that (sensibly) doesn’t have register_globals set, whereupon nothing much happens at all.

Fortunately, a couple of easy modifications script using the predefined variables syntax now in use since PHP 4.1.0 will take care of this.

First up, the code in “STAGE ONE: Setting styles” for the switcher.php file should read:


<?php
setcookie("sitestyle", $_GET["set"], time() + 31536000, "/", "yourdomain.com", 0);
header("Location: $HTTP_REFERER");
?>

Secondly, the code in “STAGE TWO: Detecting styles” should be:


<link rel="stylesheet" type="text/css" media="screen" title="User
Defined Style"
href="<?php echo isset($_COOKIE['sitestyle']) ? $_COOKIE['sitestyle'] : 'defaultstyle' ?>.css" />

And that should be just about it.

PHP, RSS and del.icio.us

Things to remember when doing dumb things like moving your site to PHP just to get a cool RSS feed:

XML declarations in XHTML 1.1

Loons like me who set up with an XHTML 1.1 DOCTYPE declaration also need an appropriate XML declaration at the start of the document too:

<?xml version="1.0" charset="UTF-8"?>

Putting this into a PHP file causes the server to blindly assume that that must be PHP code and (duh) falls over at the first hurdle. There seems to be a multitude of ways around this, but the one that worked for me was the simplest:

<?php echo "<?xml version=\"1.0\" charset=\"UTF-8\"?>

Fixing broken URL’s for extinct .html pages

At first, I toyed with the idea of some rules in the httpd.conf file but frankly I couldn’t be arsed.

In the event, I wrote a custom 404 ErrorDocument that looks at the REQUEST_URI, has a look to see if it’s got the word “archives” in it, and if so, do a quick search and replace job on it. Something like:


if (strstr($REQUEST_URI, archives)) {
  $oldpage = $REQUEST_URI;
  $newpage = ereg_replace(".html", ".php", $oldpage);
}

If I were I being a good person, I’d check the local file system for the presence of the document, but in this instance, I know the documents are there for sure and so I don’t really care too much.

Escaping URL’s from del.icio.us feeds

And just as you think it’s all wrapped up… the W3C Validator decided to have a jolly good moan about the occasional URL I was pulling in from the del.icio.us RSS feed that had unescaped ampersands in it. Again, PHP and regex functions sorted that one out (I’m using the excellent
Magpie RSS to take care of parsing the feeds otherwise):

$href = ereg_replace("&", "&amp;", $item['link']);

Storing the PHP session ID in a form

If you’ve chosen not to use cookies for PHP sessions, you can append the SID of the session to a URL link in order to keep track of it.

If you want to keep track of SID on page that’s accessed by a form submission, the little code snippet below will strip out the PHPSESSID= from the variable for use as a hidden form value:

$sid = substr(SID, (strpos(SID, "=") + 1), strlen(SID));

And then to use it in your form, add the code below somewhere:

<input type="hidden" name="PHPSESSID" value="<?= $sid ?>" />

delicious

Disclaimer

The opinions expressed on Undercrank.com are personal and do not represent Skype or any other organisation I belong to.

Flickr

Mark McLaughlin posted a photo:One of the more curious sights at Macworld - it takes a line input and attaches to a helmet, sending vibrations through that so that you get music 'in your head' but still leave your ears exposed.Mark McLaughlin posted a photo:He also wishes you a Happy President's Day, too.Mark McLaughlin posted a photo:Outside the App Planet (Hall 7) at Mobile World Congress 2010Mark McLaughlin posted a photo:Stunning light fitting inside "El Principal" restaurant in Barcelona.Mark McLaughlin posted a photo:I really actually thought I'd seen it all - but the award for most nerdy number plate ever goes to...Mark McLaughlin posted a photo:Mark McLaughlin posted a photo:Mark McLaughlin posted a photo:Mark McLaughlin posted a video: