Small fix for WordPress XML-RPC

I had the idea that I might photo blog more if there was an easy way to get photos off my iPhone and into a blog post.  The easiest way would be to e-mail the photo someplace for WordPress to get it.  Unfortunately, most of the e-mail to blog post plugins (and the built-in stuff) just sucks for my need.

I decided to look at the XML-RPC API to see if I could get it done that way, and then write a script to be called out of procmail to create the mail.  There is a function there that will do what I want, wp.uploadFile aka metaWeblog.newMediaObject.  The specification for that call says that the file being uploaded must be Base64 encoded.  No problem, a few line of ruby later and I have everything ready to test an upload.  The file goes up, but its unviewable in a browser.  A quick check of the file on the server and its revealed to be a text file filled with Baes64 looking data.  Somewhere along the line it wasn’t being decoded.

After about an hour of screwing around, I determined it wasn’t anything obvious in my code, so I thought I’d look at the code for WordPress 2.5.1 to see if I missed anything obvious.  In reading their code, I found that the WordPress folks forgot something obvious, their code never Base64 decodes it before it writes it to a file.  A quick one-line change later, and *boom* I’m off.

Here’s the patch in case its useful to anyone else. I’ll have the script up when I’m done with it.

(Also, in a small bit of embarrassment, I must admit fixing this took me 10 minutes longer than it should because I forgot ; is end of statement in PHP.)

Index: xmlrpc.php
===================================================================
--- xmlrpc.php  (revision 7840)
+++ xmlrpc.php  (working copy)
@@ -1880,6 +1880,10 @@
                        $name = "wpid{$old_file->ID}-{$filename}";
                }
 
+                # The specification says that this is base64 encoded,
+                # we should really decode it.
+                $bits = base64_decode($bits);
+
                $upload = wp_upload_bits($name, $type, $bits);
                if ( ! empty($upload['error']) ) {
                        $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']);

Beer, it kicks ass!

There is an awesome bar in in Washington, D.C. called the Brickskeller. Its my kinda place.  Hell, even their domain name is lovethebeer.com. They claim to have the world’s largest beer selection and it certainly looked like they did. Unfortunately, due to season rotation and popularity, some of what we tried to order wasn’t available.

Inspired by the Wingin’ It beer photo stream and my visit to the Brickskeller last night, I’ve decided to start doing a similar thing here. I forgot to get a picture of the Orval Trappist Ale I had last night, but luckily, I can snag one off their web site.

I also had an Oskar Blues Ten Fidy again, mostly because I thought I’d never get that awesomeness again. The guys at the table next to us suggested a Maredsous Dubbel or Triple. I went with the Dubbel. It was awesome.

On a geek note, right now I’m just uploading this into wordpress. I’m not sold on using flickr, but I’m not sure why.

Sunday fun

  1. Shutdown
  2. <install new/replacement disk>
  3. fdisk
  4. mkswap
  5. umount /boot
  6. dd
  7. e2fsck && resize2fs
  8. mount -o remount,ro /
  9. dd
  10. e2fsck && resize2fs
  11. mount -o remount,rw /
  12. pvcreate
  13. vgextend
  14. pvmove (wait a long long long time for 174 GB, especially with disk read errors, to move)
  15. vgreduce
  16. shutdown
  17. remove old and busted, put new hotness in as primary disk
  18. boot into rescue disk
  19. mount / /usr
  20. grub-install /dev/hda1
  21. ms-sys -m /dev/hda
  22. vi /etc/fstab
  23. shutdown -r now
  24. Party like its 1999 or, if you like assembler better:   GGB

New panic in the streets!

I read this in the dead tree edition of the Tribune yesterday and forgot to make a post bitching about it. Luckily, Chicagoist was there: Congressman Says Second Life Could Expose Kids To Porn, Predators.

Basically, Mark Kirk got his panties all up in a bunch because Second Life have some adult stuff going on and in his opionin its too easy for minors to get into that area. While I understand his concern, I disagree that the government should be stepping in here, even with something as minor as an FTP consumer alert. Parents should be monitoring what their children are doing on-line. If you can’t take the time and/or education commitment to do that as a parent, disable your internet access.

The part that really chaps my hide is the following (quoted from the Tribune):

Kirk said he knew of no cases in which children were targeted by sexual predators on Second Life, but he said he considers the virtual world an emerging danger.

So…there’s been no reported problems, or at least none visible to him, but OH MY GOD! RAISE THE ALARM BELLS!  THE CHILDRENS!  WON’T SOMEONE THINKS OF THEM??!?!?!!!  I hate election year fear-based  attention-getting pandering.

For the record, I have no particular love for Second Live either.  I’ve played with it a bit but I don’t get all the hype around it.  I must just be getting old.

Great syntax highlighting plugin for WordPress

At times, I think I spend more time writing about using wordpress than actually using it sometimes. I’ll need to fix that. Today, thanks to WordPress’s dashboard, I came across the WP-Codebox plugin. THanks to GeSHI, it can color up a lot of languages and fixes some problems I’ve had with other plugins. Honestly, I’ve never been satisfied with any of them. I think this could change that.

Just to show it off, I present to you some random ruby I wrote the other day when I was working on something. I’ll leave it to you to guess what I’m doing and why with this code. (And I also think I could do it better than using a while loop, but I was able to bang it out quickly for what I needed.)

#!/usr/bin/env ruby
require 'fileutils'

srand(Time.now.to_i)
offset = 214

files = Dir['*']

count = 1
while !files.empty?
  file = files.delete_at(rand(files.size))
  extention = File.extname(file).downcase
  name = sprintf('%d%s', count + offset, extention)
  puts "#{file} -> #{name}"
  FileUtils.move(file, name)
  count += 1
end

Keith's attempts to fix the cable of life