How to make your own Lifestream Blog

Posted on January 20th, 2008 at 6:13 pm

tumblr and code igniter

WARNING: This tutorial is more for the nerds among us. It’s not really for public consumption yet. If terms like SVN, config files and MVC confound or frighten you, it’s probably best to wait until I can wrap everything up into a more mainstream-friendly package.

Hokay. A little bit of explanation.

What I’ve done for Yongfook.com 2008 is use Tumblr to manage my content, and Code Igniter to write a simple application that grabs my Tumblr data via their API (updating every hour or so), store it in my own database, and display everything all nice and neat-like. That’s it. Such a simple solution, but it seems to be working very nicely. First lets get some questions out of the way…

Uh, doesn’t Tumblr have like a “use your own domain feature” anyway?

Yes, yes it does. However I wanted to have more control over how the data is displayed. Also having everything on my own server allows me to control the url structure to my liking. Plus it was fun to write the app.

Can’t you just do this with the Tumblr “embed” feature?

Kinda. But then search engines would just be seeing a javascript tag on your page - I want search engines to see actual content.

Does Tumblr or Code Igniter mind that you’ve done this?

I emailed Tumblr and they seemed cool with it. Code Igniter is an Open Source framework and I have fully attributed them and kept their license intact and whatnot. So everything should be cool.

ROUND…1…FIGHT!

Disclaimer: I make no claims that this will actually work. Works on my local and remote server though. Also, the app is very barebones right now - it does not feature a nice default template or anything. Yet. If you have CSS skills and working knowledge of php, it should be very easy for you to skin the app to your liking, however. I recommend you try this out on a local test server. Don’t be crazy and test this out on a live, production server. If you need an easy local server solution I recommend MAMP if you have a mac.

Here’s what you’ll need to try out the app.

  1. A server with at least php 5.1
  2. A Tumblr account, preferably one that you’ve already put some content into.
  3. A little patience and low expectations.

Instructions

  1. Check out the application from its subversion repository by running this command svn checkout http://stampychan.googlecode.com/svn/trunk/ stampychan-read-only

  2. /trunk is your new root location

  3. You need to create two folders and make them server-writable - /public/images/item_images, and /system/cache

  4. There’s an example table schema in /system/application/config/sql.php - create this table on your db. It’s just one table and it is very simple.

  5. There’s a db config file in /system/application/config/database.php - populate it with your db details.

  6. There’s another config file in /system/application/config/tumble.php - just a few more things to fill out.

That’s basically it. Now, to import your Tumblr data, all you need to do is point your browser to /cron/import/your-password-from-tumble.php and it will import stuff from Tumblr and stick it in the db. Set up a cron job on this to import your Tumblr data periodically.

To poke around with the layout, you just need to edit the files in /system/application/views/. I store static files such as css in the /public/ folder so if you want to edit the CSS, look in /public/css/.

What is this app doing?

Most of the magic happens in /system/application/controllers/cron.php.

This basically takes your Tumblr JSON stream, pulls out the stuff it wants and puts the data into the db. As you can see, the db structure is very basic, but there’s kind of a reason for that. There are so many possible different data types (photo, video, text etc etc) and the possibility of this increasing in the future that we’ll get into a mess trying to define the data in terms of fields. So we’re just creating a data object, serialising it and putting it into an item_data field. This does mean that we can’t get really granular results when pulling out data (e.g. I only want photos that are in landscape mode where the caption starts with an ‘A’!) but that’s not really the point of a lifestream anyway. We can still filter the results by data type (video, photo, blog etc) and I think that’s enough for our purpose.

Another current drawback is that the cron script is executable by anyone. In an ideal world we would take the cron script outside the document root so it is only executable by ourselves. To prevent malicious use, the cron import is protected by a password that you set, so providing your password isn’t compromised, no one can initiate an import except you.

Anyway. I’m tired. Go and have a play and let me know if it blows up your server (but don’t hold me accountable…)

Yongfook

Posted on January 20 at 6:13 pm | Original Link »