TwentyEleven With Easy Rotating Header Images

I have a secondary blog which I wanted to have some special header images. One nice thing about the new default WordPress theme, TwentyEleven, is that you can have a couple of header images and rotate them randomly. A bad thing about the new default WordPress theme is that it’s annoying adding new header images.

At first I got this post about adding your own images. One thing I did a bit different was the way I was generating thumbnails with the same name of the image, but in a different directory. Because of that, all I really needed was the image name. Thus, my wptis_new_default_header_images() turned into:

function wptips_new_default_header_images() {
    $dir = get_bloginfo('stylesheet_directory');
    $headers = array(
        'image1',
        'image2',
        'image3',
        'image4'
    );

    $images = array()
    foreach($headers as $filename) {
        $images[] = array(
            'url' => "$dir/images/$filename.jpg",
            'thumbnail_url' => "$dir/images/thumbs/$filename.jpg",
            'description' => __($filename, 'twentyelevenheaders')
        );
    }
    register_default_headers($images);
}

This way, when I needed to add a new header, all I had to do was upload it to the theme package (with the thumbnail) and edit the $headers array to add the new filename.

But that was a bit annoying ’cause, well, I had to create the thumbnail, upload both the image and the thumbnail and then edit the function again. That’s when it occurred to me that I could make a page, add a gallery to it and then make the theme load the images from that gallery. That way, I could use WordPress itself to upload the images and let it create the thumbnails. The result was this:

function wptips_new_default_header_images() {
	$child2011_dir = get_bloginfo('stylesheet_directory');
	$images = array();

	$page = get_page_by_title('The Headers');
	$attachments = get_children(
		array(
			'post_parent' => $page->ID,
			'post_type' => 'attachment',
			'orderby' => 'menu_order ASC, ID',
			'order' => 'DESC'
		) 
	);
	foreach($attachments as $id => $info) {
		$image_id = $info->ID;
		$url = wp_get_attachment_image_src($image_id, 'full');
		$thumb = wp_get_attachment_image_src($image_id, 'medium');
		$images[] = array(
			'url' => $url[0],
			'thumbnail_url' =>  $thumb[0],
			'description' => __($info->post_title, 'twentyelevenheaders')
		);
	}

    register_default_headers($images);
}

After that, I created a page named “The Headers” and uploaded all images I wanted (following the guildelines of 1000×288) and let WordPress take care of the rest, including saving them on the server and creating the thumbnail. The thumbnail is a bit larger than the normal size, but that’s not a big issue IMHO.

Anyway, if you’re interested, here is the theme. Install like any other WordPress theme, but you’ll need a page named “The Headers” for it to work (or create a page and change the name in the code).

GPL and the web

A few years ago (two or three), I saw Richard Stallman at FISL where he said that things like Webmail were bad ’cause you don’t have any control over the software it runs in the server. In a way, he is right: How do you have any control over your data if you don’t have any control over your software? How can you be sure that the server isn’t doing something nasty with your information since you have no way to request the source code?

Requesting the source code is one of your rights if you are using a GPL-licensed software. That way, you can be sure that the application is not sending your information to someone else or looking for things it shouldn’t. But the GPL says that distributed software should have its code available; in a web 2.0 world, nobody is distributing any software: it simply is there. Therefore, even if you run a GPL application, do lots of modifications, because you’re not distributing it, you don’t need to make your changes available to the world.

The thing that was bothering me, though, is related to some web apps/websites I used at some point. They had this pretty cool thing and I was wondering “Is that something I know, like WordPress, Drupal, Joomla or whatever?” but, in the end, I couldn’t find anything that would say what they were using in the backend. And, just now, I was wondering how the GPL would apply to such websites.

Besides the GPL, there is another very useful license: The modified BSD license or simply “BSD”. The only rule the BSD license requires (compared to the “5 freedoms” GPL enforces) is that you can’t remove the copyright from the original authors. You may add your name, but the original copyright must appear somewhere. I wondered, then, if the GPL would have such requirement. I’m not a lawyer, but I think this does:

5. Conveying Modified Source Versions.
[…]
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.

That, to me, sounds exactly like the BSD. So, if you’re using a GPL software in your webserver, you must point, somewhere, that the engine behind your powerful site is copyright the original authors.

Now you must ask yourself this: How many websites out there are using WordPress with a modified theme that completely removed the “Powered by WordPress”? Or sites that chose (not sure why) the GPL version of the jQuery and didn’t mention that anywhere?

WordPress and the Cruft

I really like WordPress, but NanoBlogger always amazed me for its simplicity. It’s not like I update my blog every hour or something to have something rendering the same pages again (and dynamic content, like the Last.fm, Twitter and Del.icio.us widgets don’t behave properly under WordPress cache plugin — or, at least, it didn’t work when I tried last time.)

So, just for the fun of it, I decided to try to write a “WordPress 2 NanoBlogger” converter. The first is get a copy of the database, so I have the data to convert in first place. Simple MySQL-dump would be enough to me (well, not completely necessary, but I still don’t have internet at home and I can’t connect to my database without the data.)

Dump in hand, I decided to take a look at it. The amount of cruft on it is really impressive. I still have things about my LJ-exporter, which isn’t being used for a year already. And Twitter Tools is keeping copies of all my Tweets.

I know it’s not the normal WordPress use, but I guess it should have some option to clean up its database (at some request in the admin interface.)

‘Cause an idea is a terrible thing to waste

[2:23:32 PM] Julio Biason says: now I have two projects in my head
[2:23:46 PM] Julio Biason says: first one is a image gallery (much like Gallery), using tags, written in python
[2:23:51 PM] Gerald Kaszuba says: ooh
[2:23:58 PM] Julio Biason says: and something that I would call “Replicator”.
[2:24:02 PM] Gerald Kaszuba says: heh
[2:24:15 PM] Julio Biason says: replicator is my idea of “update all your social things in just one place”
[2:24:21 PM] Gerald Kaszuba says: nice
[2:24:43 PM] Julio Biason says: say, you want to update your picture? Just provide your password for, say, last.fm, facebook, orkut, twitter, pownce and it will upload to all of them and update all profiles.
[2:25:09 PM] Julio Biason says: want to write a blog post? no worries, we replicate it in your wordpress and last.fm (if you point that it is music related)
[2:25:15 PM] Gerald Kaszuba says: that’s quite cool actually
[2:25:18 PM] Julio Biason says: pictures? upload to orkut and flickr
[2:26:34 PM] Julio Biason says: i’m still not sure if I do it as an Gtk application, Cocoa application or a web application…
[2:26:49 PM] Gerald Kaszuba says: id go for web app myself
[2:27:22 PM] Julio Biason says: The good thing about being a web app is that all the other things are web apps too
[2:27:51 PM] Gerald Kaszuba says: well yeah… and accessable from anywhere
[2:27:57 PM] Julio Biason says: the bad thing is that i’ll have to save your passwords to access the other applications, and I’m not keen to putting my password somewhere (even if I wrote the app)
[2:28:16 PM] Gerald Kaszuba says: u can get them to type it in everytime! :)
[2:28:19 PM] Julio Biason says: Gtk would be a good choice, as I could (hopefully) easyly port to all other applications (using pygtk)
[2:28:33 PM] Julio Biason says: yeah, I could. but that would be annoying…
[2:28:38 PM] Gerald Kaszuba says: yeah

By the way, if you like those ideas, feel free to drop me a note and we can start working on them (I have everything set up for TAGallery, the web gallery, except that I don’t have any code yet.)

Give to Caesar what belongs to Caesar

One of the things that pisses me off is when someone uses open source and don’t give the credit to the authors.

This happens a lot with web applications.

Several times I looked at some site and thought “hey, that’s a nice engine those guys got there”, only to find, in some weird way, that it is just a theme for WordPress. Honestly, that’s probably the least credited open source project ever (well, maybe after Apache and PHP, anyway). Several themes around remove the “powered by WordPress” completely.

Come on! It is not that hard to add a simple “powered by” in the bottom of the page…