Are we going in the right direction?…

A very well respected member of the web world, Andy Rutledge, has recently been asking some very interesting questions. Firstly about social (or anti-social) media and secondly the moral questions surrounding technology being the way we are slowly killing ourselves.

Both essays are well worth reading. And you know what, I have to agree with a lot of the points he makes. We’re rapidly approaching the point where a large percentage of the Western population have a lack of basic communication and real-life social skills, responsibility and awareness of wider isues because of the comfortable cacoon that the current technological civilisation affords them. It should not be that way.

There’s a fable about the frog sat in a pan of water I heard once. As the water gradually warms up he enjoys himself, thinking how lucky he is to have his own private heated pool. It’s only when the water is reaching boiling point he realises his mistake. How far are we from boiling point?

Off-road web technologies…

The internet is often described as an information superhighway. And on any highway there are vehicles, lots of different types of vehicles. I started to think about this over the last few days and realised that the two (server-side development) technologies I spend most of my time using these days represent two wildly different ‘vehicles’. And because I’m not averse to writing ill-thought out ramblings about the web, here are my thoughts.

ASP.net is a SUV

ASP.net is Microsoft latest attempt to take a lead role in web development. It’s a newer, shinier and much more powerful version of the old Classic ASP which I spent too many years using (and still do, regularly). It’s big and clever, does all manner of things for you, comes with a huge array of complex features, and is very picky what it runs on. The latest version of IIS for Windows only, please. (And yes, I know about Mono. Just bear with me.)

In short, ASP.net is a lot like this:

Sports utility vehicle

Yes, the Sports Utility Vehicle. Big, shiny, covered in chrome and brushed titanium. An interior made of plush leather with rare wood facias, and lots of slick gadgets. They say it will take you off-road anywhere, but let’s face it: these things are only owned by rich people living in posh suburbia. The dreaded Chelsea tractor factor, as some people have said.

They guzzle fuel, pollute the landscape, and if something goes wrong it goes really wrong and needs an expensive trip to the specialist garage to mend. No hacking away with a spanner and roll of gaffa tape on these, no way. But they have their good points. They are incredibly sophisticated, so don’t worry about reversing into a lamp-post because before you hit it a polite computerised voice will say “You’re just about to hit a lamp-post. Are you sure you want to do that?” and then offer you a latte.

They are comfortable; really really comfortable. You get so used to being inside one that when you have to drive in a Lesser Automobile you feel dirty. In fact they are so clean and nice to be in that you forget there’s an engine with messy things like oil and fuel squirting around in little tubes. Unscrew a little cap to check the oil? Not me, I just say “E-mail me a current oil level reading, car” and it does it.

And, let’s face it, everybody is jealous. They see me driving one of these and they know I’ve Made It. I must be some celebrity, or a director of a large company, because those sorts of people are the sorts of people to have these kinds of cars. I see them stare at the car from behind my tinted windows, as I press a touch-sensitive button to turn the air-con down just a fraction. And when I get home, I just twitch my left nostril a bit and the wrought-iron gates leading to my 400-yard drive swing open, and my digital TV automatically turns itself on to Footballers Wives. Bliss.

PHP is a Land Rover

PHP, on the other hand, is an old technology. Originally put together by just one bloke, and is now one of the foremost technologies in use on the web. From the page linked above:

Today, PHP is being used by hundreds of thousands of developers (estimated), and several million sites report as having it installed, which accounts for over 20% of the domains on the Internet.

Its open source roots, huge collective of developers, and ‘hackable’ nature have meant it is often the first server-side technology beginners have been able to get into without a steep learning curve.

In essence, PHP is quite like this:

Land Rover, the original and best

The classic British Land Rover. Originally built to be as simple to fix as possible, it has been a stalwart of not just the British Army, but many armies around the world, for over 50 years. It’s basic, uncomplicated, rugged and tough – exactly what you need for driving across difficult terrain. It’s so modular that what you can’t fix or find spares for you could probably make yourself. In fact I have a friend who makes spares for his Land Rovers in his garage using nothing but some simple tools.

So there you are, parts of your engine strewn across the desert floor after a particularly amorous rhino mistook you for a mate. It could have been worse – you have a set of spanners, a roll of gaffa tape and a flask of tea. Two hours later you’re back on your merry way, stroking your goatee in satisfaction and thinking of your collection of model steal engines waiting for you back in good old Blighty. What-ho.

Landys are classics, up there with Spitfires and red telephone boxes, pints of bitter and fish ‘n’ chips. They are reliable, and even when it does break you don’t need Jim to Fix It for you). But they aren’t comfortable or plush or stylish. They aren’t the sort of thing you turn up in to take a young lady to a restaurant. But they are just the thing to pull a posh SUV out of a muddy field with.

People also stare when you drive a Landy. Most people wonder why you don’t buy a ‘decent’ car, but those in the know understand. It’s not about the bells and whistles, the leather and chrome. It’s about an intimacy with the vehicle – knowing the nooks and crannies, knowing not just what everything does, but how and why. Landy’s hardly impress anyone, and turning up to a high-powered sales meeting in one will make people think you’re losing the plot. But put one up a mountain or in a desert and you’ll see why the heard of a free beast must run wild.

Image resizing with PHP…

One of the many things I love about the PHP scripting language is its support for image manipulation through the GD library. You want thumbnails? You got thumbnails. You want watermarks? You got watermarks. You want to create duplicates of 2000+ images in a folder with a slightly different filename, and a limited width/height? Use this script:

function resizeImage($source, $target, $width, $height){
$quality = 65;
$size = getimagesize($source);
// scale evenly
$ratio = $size[0] / $size[1];
if ($ratio >= 1){
$scale = $width / $size[0];
} else {
$scale = $height / $size[1];
}
// make sure its not smaller to begin with!
if ($width >= $size[0] && $height >= $size[1]){
$scale = 1;
}
$im_in = imagecreatefromjpeg ($source);
$im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]);
imagejpeg($im_out, $target, $quality);
imagedestroy($im_out);
imagedestroy($im_in);
}
foreach (glob("images/products/*_l.jpg") as $filename) {
$medium = str_replace("_l.jpg", "_m.jpg", $filename);
resizeImage($filename, $medium, 125, 100);
}

Notice the neat ‘glob’ function? That, my dear readers, is *nix brevity at its best.

Content management – getting fresher…

I’ve been doing some more thinking about content management idea and I’ve figured out how – I think – the database is going to work. Bear with me, because this might get pretty geeky.

Firstly I wanted to have an unlimited number of items; an item could be a page, a blog, a gallery, a forum etc. It doesn’t really matter what type the item is, but it is VERY important that we understand the relationships between them. So the Parent ID thing I mentioned in my original post has immense importance. Without that, there is no system. Let me give you a quick example in case you dont get what I mean.

I have a homepage for my site, which is called “homepage”. It has an ID of 1 and a Parent ID of 0. The ID is 1 because it’s the first item in my database. The Parent ID is 0 because if is the lowest level item.

I have another item called “about” which has an ID of 2 and a Parent ID of 1. The ID of 2 is because it’s the second item to be added to my database. The Parent ID is 1 because it’s a child of the item with ID 1 – homepage. This way we can build up hierarchical relationships between any number of items. Spiffing.

My tables will look more than a little like this:

Table: items

id (auto integer)
item_type (id of the type of item this is, from the item_types table)
status (the id of the status of the item, from the statuses table)
parent_id (the id of the parent of this item)
name (the name for this item)
permalink (the URL-safe version of the name, used for clean URLs)
created_on (datestamp of the create date)
created_by (id of the user that created this item, from the users table)

Table: statuses

id (auto integer)
status (the description of this status)

status values: [draft, public, private, deleted]

Table: item_types

id (auto integer)
item_type (the description of this type, more in this later)

I’ll let you guess what the users table will look like.

So, we have a basic database. Now what we need to do is start populating it with some data. But where? There doesn’t seem to be any fields in the items table to store the page content in, so where does it go? Well, I’m glad you asked, because the answer is ‘it depends’.

What content gets displayed when each item is called depends entirely on the type of that item. We know what type each item is because it’s stored in the database, but what types could we have – and what data can be attached to each type? Here’s a quick list.

Type: page
Data: page_title [text], page_description [text], page_keywords [text], page_body [text], allow_comments [bool]

Type: blog
Data: blog_title [text], blog_description [text], allow_comments [bool]

Type: blog_entry
Data: entry_title [text], entry_body [text], allow_comments [bool], categories [array]

Type: blog_comment
Data: commenter_name [text], commenter_email [text], commenter_website [text], commernter_ip [text], comment_body [text]

Type: gallery
Data: gallery_title [text], gallery_body [text]

Type: photo_set (just to make it clear, I thought each gallery – you could have more than one, of course – could have multiple photo sets)
Data: set_title [text], set_description [text], allow_comments [bool]

Type: photo
Data: photo_name [text], photo_description [text], allow_comments [bool]

Type: forum
Data: forum_title [text], forum_description [text], anonymous_posts [bool]

Type: forum_thread
Data: thread_title [text]

Type: forum_post
Data: post_body [text], poster_name [text], poster_email [text], poster_website [text], poster_ip [text]

So, of course, there could be more types than this. And, of course, quite a few of the types share the same kind of data which could well be normalised in some table somewhere. But hopefully you see that most item types are pretty similar in the data they require. The lesson from all of this is: do we really need different tables for all of these data types? I don’t think we do.

One last note. This system borrows heavily from the ethos of 37signals Ruby on Rails which is ‘convention over configuration’. That makes a lot of sense to me.

Increasing user interaction with websites…

I recently gave a presentation entitled “Increasing user interaction with websites”. Because I’m all into savig the earth, recycling and being a Jolly Nice Chap, here it is.

I did it in the quite wonderful S5 system by the esteemed Eric Meyer which I will no doubt be using again very soon, and works best in full-screen mode. Try pressing F11 on your keyboard, you might like it.