Archive for October, 2007

Fixing wordpress RSS XML parsing errors

Saturday, October 20th, 2007

Wordpress RSS feeds can be annoying. Really annoying. If you install a bad plugin, theme, or even edit some of the existing php files you might find your RSS feeds start getting this parsing error.

XML Parsing Error: xml declaration not at start of external entity
Line Number 3, Column 1:<?xml version="1.0" encoding="UTF-8"?>

You might find that enabling output buffering for your RSS feeds might sort you out, as suggested by J Wynia. But unfortunately it didn’t do it for me.

So, go to the source and fix up the files causing you problems, with the following perl script. It will check each of your php files for any that have extra line feeds at the start, or end - and remove them. You’ll need SSH / command line access for this, as well as perl installed.

Use it at your own risk. It worked for me, but is otherwise untested - so, make a backup first :)

Instructions

  1. Backup your wordpress installation
  2. Download the script to the root directory of your wordpress installation.
  3. cd to your installation directory.
  4. Run the script: perl fix-rss-xml-spacing.txt.
  5. Fingers crossed, your RSS feeds will now work again (and hopefully, so will the rest of your blog).

Good luck!

Geonaming your Geotags - Automatic picture captions

Saturday, October 6th, 2007

This time last year, I wrote about how to Geotag your photos using a simple GPS device and oodles of free software. Not much has changed in that process since, except now there’s a lot more software to choose from and the clever folks over at Trackstick.com have made it a lot easier to export your GPX tracks.

The spatially-aware web is producing a lot more services for us to use, and now Geonames.org some excellent reverse geocoding functionality. That’s the process of taking geo-data (such as longitude and latitude) and getting place names back. Which is really cool for tagging, titling or adding descriptions to your geocoded pictures.

They provide an impressive array of web services in both JSON and XML ranging from postal code searches, to reverse geocoding based on the community-based Wikipedia entries. And if that’s not enough for you, you can download a copy of their huge database and manipulate it off-line however you want.

So me, I wrote some JavaScript to take advantage of the reverse geocoding and tied it into the Blakepics Gallery2 Tags module. I’ll take the Wikipedia entries as an example, because that returns the most landmarks for me. The example code at the bottom of the page actually makes use of two more web services in addition.


The URL to call the web service is pretty simple enough:

var url = "http://ws.geonames.org/findNearbyWikipediaJSON?lat=" + lat + "&lng=" + lon + "&radius=10";

I’ve kept everything in JavaScript rather than building any back-end code whatsoever, so you need to make sure to use the JSON web services and take advantage of the script tags to avoid any cross-domain security policies. The JSONScriptRequest library can be a powerful ally here. This leaves my server to do more important things, but it all depends on your needs for the app.

url += "&callback=showWikipediaNames";
bObj3 = new JSONscriptRequest(url);
// Build the dynamic script tag
bObj3.buildScriptTag();
// Add the script tag to the page
bObj3.addScriptTag();

Then on the callback
function showWikipediaNames(wikijsonData) {
var wikiobjects = wikijsonData.geonames;
if (wikijsonData.geonames) {
for (var i=0;i<wikiobjects.length;i++) {
addSuggestion(wikiobjects[i].title)
}
}
bObj3.removeScriptTag();
}

With me so far? The final step in the process is to add the call to the JavaScript into your Gallery2 templates.

<a href="#" onclick="return showGeoNameOptions(this, {$block.gpsinfo.LoadGPSInfo.lat}, {$block.gpsinfo.LoadGPSInfo.lon});">GeoNames</a>

And before you know it, you have suggestions from geonames on how to tag your photos. Now you can go away and make it suggest some titles and descriptions too. If anyone’s interested in packaging this up into a slightly better Gallery module (or any other application), drop me a line. If this is enough for you, download my example and use it as you see fit.

Download

Pre-requisites