How to put your own blog on iPhone...

As you know, iPhone has Safari browser onboard. It's pretty neat and great working... but sites with huge layouts don't look good on small iPhone screen. When you have own blog it would be good to display it in customized way.
Today almost all blogs have RSS Feeds so if we want to display our blog in cusomized, iPhone ready look it's just to put blog's feed through some RSS parser and display it as iPhone ready web page. Let's use iui - project started by Joe Hewitt - creator of firebug. It's a simple JavaScript framework for iPhone web pages.
So, we have iui now we need some PHP RSS reader. We'll use SimpleXMLObject class because it's ... simple.

As you can notice in php code we have function calls to something called xcache - it's very nice plugin for php speeding up your code by doing magic opcode caching. But for now we'll use different advantage of cache - you can store variables just in your server memory and get access to it on different php file calls. I this case we use this to download RSS feed once and store it for a while. So if you refresh your browser or some one else will go on your blog we do not need to download feed again.

Now we have our blog's feed and we can display it in nice iui internface.
Putting all things together we have pretty simple and neat iPhone blog: http://botmonster.com/iFeed/
Now, let's make browser detection - if browser is iPhone's Safari redirect user to our "iPhone ready" blog page. Just paste this JavaScript snippet into html section of your blog template. Replace "feedURL=" with link to your blog's feed.

It's very simple detection, if you need more sophisticated detection I'll recommend using this webkit detect script Just try to enter this address into your iPhone: blog.botmonster.com - you'll be redirect into iFeed page and you will see something like this:

You can download all iFeed code from google code at http://code.google.com/p/ifeed/
Available under MIT licence.

9 komentarze:

JimL said...

This is excellent - You don't explicitly say so or in the Google Download instructions, but XCache is mandatory to be able to run the code - yes ?

botmonster said...

It's not mandatory, as you can see in code I use $cache = function_exists('xcache_set'); so when we do not have xcache everything should work just fine.

JimL said...

Hmmm I'm obviously doing something wrong then as I get an error retrieving the feed URL. Does the Feed URL look like the below, if for example Digg was the feed you were after ?

$feedURL = isset($_GET['http://www.digg.com/rss/index.xml']) ? $_GET['http://www.digg.com/rss/index.xml'] : '';

Anonymous said...

I like this, nice and simple. However i'm getting the same error as jiml. Can you please explain how the $feedURL works? And also how it should be setup? Eg the Digg example above.

Cheers

Brian said...

Also getting the same error message as other commenters have posted after entering my XML feed... I also did exactly what jiml did to test with the same result... Anyone figured this out by chance?

Anonymous said...

Unfortunately I still haven't had much luck, I've tried a few things but my coding skills are pretty basic...

Also wondering what:


$feed = simplexml_load_file($feedURL);


is in reference too on the main blog? I can't find it in the PHP file and wonder if this is where we are going wrong?

Anonymous said...

Had some small success. I've managed to get it running locally but only some RSS feeds work. The example belowe works a treat locally.

$feedURL = isset ($_GET['feedURL']) ? $_GET['feedURL'] : 'http://feeds.feedburner.com/BotmonstersWired?format=xml';

That works fine locally however if I replace Botmonsters RSS feed for Diggs I get the error.

The feeds that do work locally don't work when posted on my hosted site. The main difference would be the version of PHP. I'm running 5 and my host is running 4.3.4. Not sure if that makes any difference...

hufuntw said...

It's really a good work. But, some questions.

When I click hyperlink in first page, it works.
After entering detail page, I want to click other hyperlink in detail page, but there is something wrong, no reaction....
hyperlink no reaction,

Iain said...

I am also having a feed retrieval error. Did this get resolved? I have only seen comment posts up to 2008.
My feed is http://www.movida-london.com/eventscal/xml.php if anyone is able to advise that would be great.