Category Archives: Wordpress

Twitter to WordPress to Facebook

(Skip the lecture, go straight to the instructions — but note the update.)

I’m yet to be convinced that microblogging (eg Twitter, or those status updates in Facebook) is genuinely useful. Maybe, maybe not. But I’m willing to try it out.

Problem is of course that if you use multiple services, you don’t want to be having to update them all individually. If such a concept is going to work, you’ve got to be able to update once and have it cascade to everywhere.

Facebook has an app to push updates out to Twitter. Which would be fine, but for those outside North America, you can’t update your Facebook status from anywhere except within Facebook. (North Americans can use SMS from a mobile, but others can’t.) Okay, so maybe you’d want to do it mostly when in front of a computer anyway, but I do like about Twitter than you can update from anywhere… anybody can SMS a number (it’s based in the UK, so for me it’s costing 50 cents… so I’d better not go mad using it) so no fiddling with mobile web access just to post an update. Twitter also takes updates via IM (such as GTalk and Jabber). I also like that it’s open; people can see what’s going on without registering.

I normally hate words like synergy and leverage and convergence, but that’s what’s gone on here. Alex King has written code that updates WordPress from Twitter every 15 minutes. Christian Flickinger has written code that updates Facebook using PHP, with a hack using the Curl library (since Facebook doesn’t actually accept inputs like this) that logs into Facebook’s mobile web page and does the business.

And Blake Brannon has put the two together, so a Tweet (that’s Web 2.0 talk for a Twitter post) will cascade to your WordPress blog, and then on to your Facebook status.

Neato, huh? Now that really is leverage. If it works. Which it does for many people, but it didn’t for me. I was having problems with Blake’s code; probably an issue with my Web ISP’s configuration. I ended up splitting it off to a separate WP plugin, which was messy, but allowed me to use the code in isolation, and figure out the problem.

It may be an issue that only affects particular versions of PHP or Apache or something — I’m no expert — but the problem was the Curl call couldn’t write to the cookies file. Creating the my_cookies.txt file and making it writable (777) and modifying the code slightly to specify where the file lived solved it. Another issue involved Curl being unable to use the FollowLocation flag, but it turned out this wasn’t needed.

I also ended up with Blake’s (modified) code in a separate file to Alex’s, rather than inserted into it as Blake intended.

So in summary

Update 2007-08-31: Blake’s been told that automated access into Facebook is against the Terms of Service. It’s unclear if Facebook will actively go chasing those who use or distribute code like this, but it would seem to pay to be cautious. Sorry.

  1. Download Alex King’s Twitter Tools and put in your wp-content/plugins directory
  2. Download twitter-wp-fb.txt. Put your Facebook details in where shown, then put it into your wp-content/plugins directory
  3. Create an empty wp-content/plugins/my_cookies.txt file and make it writable (777)
  4. Go into your WP Plugins page and activate both Twitter Tools and WP/Twitter to Facebook
  5. Go into the Twitter Tools config page and enter your Twitter credentials
  6. Cross your fingers and post something in Twitter

I think that’s all the steps. Good luck.

Thanks to Blake for his assistance on this. And to Alex and Christian, whose code this is all built on.

Easy ways to save bandwidth

After reading Jeff Atwood’s terrific post about saving bandwidth on web sites I’ve moved the Geekrant RSS feeds over to Feedburner, using Steve Smith’s mavellous WordPress Feedburner plugin, which works in WP 2.0x and 1.5x.

I also turned on HTTP compression, which in WordPress is as easy as clicking a checkbox. It not only saves you bandwidth, but users get your pages served quicker, since the bottleneck is bound to be their bandwidth, not their browser’s ability to decompress.

We’ll see how it goes. Bandwidth has been growing recently: January 2.8Gb; February 2.7Gb; March 3.4Gb. It’s not at ludicrous levels, but if it keeps climbing, I’ll end up paying more for the hosting. Hopefully this will help bring it back down.

Update 8:40pm. First thing I notice is that when reading the feed from within the Feedburner site, it doesn’t treat relative paths to images properly. I guess I’ll have to put absolute paths, ‘cos at the moment in the previous post it’s trying to load http://feeds.feedburner.com/files/2007/mediagate-mg35.jpg instead of http://www.geekrant.org/files/2007/mediagate-mg35.jpg. I wonder how it treats relative links?

Counting things in WordPress

A couple of MySql queries to count up your 2006 blog stats (as I did on my personal blog).

Count the number of posts since…

select count(*) from wp_posts
where
post_status = ‘publish’
and wp_posts.post_date >= ‘2006-01-01’

Count the post with the most comments since…

select wp_posts.ID, count(*) as wpc, wp_posts.post_title, wp_posts.post_date from wp_comments, wp_posts
where
wp_comments.comment_approved = ‘1’
and wp_comments.comment_post_ID = wp_posts.ID
and wp_posts.post_date >= ‘2006-01-01’
group by comment_post_ID
order by wpc desc

Hand-written comment spam

Amongst all the easy-to-spot robot comment spam, I’m getting a bunch that (at first glance) looks like it’s written by humans. Gone are the stupid out-of-context broken-English comments and links to drug sales. These all have comments that look like they’ve got a few milliseconds’ thought put into them, all on new posts, they all leave a rediffmail (Indian GMail-type operation) address, a 209.97. IP address, and a link to a web site featuring lots of links and no content.

So far I’ve been spiteful and kept the comments but wiped the URL link.

I wonder if they’re particularly targetting WordPress sites that haven’t yet been upgraded to use the NoFollow links.

MySql woes

We’ve got MySql problems here at Geekrant central.

MySQL said: Documentation
#1016 – Can’t open file: ‘wp_comments.MYI’ (errno: 145)

Doesn’t sound good, does it? The ISP is looking into it.

Nothing else seems to be AWOL, but I’ve taken a backup of everything just in case. Wouldn’t you know it, the backup I have of wp_comments isn’t particularly recent. Hopefully the ISP has a newer one, but if not, I’ve grabbed a bunch of comments via Newsgator’s cache. Gawd knows how I’d restore them though.

Update: Fixed. May I just say, the support guys at AussieHQ hosting are deadset legends.

WordPress Most comments

Here’s the SQL to find which of your WordPress posts have the most comments:

SELECT wp_comments.comment_post_id, count(*) as commentcount, wp_posts.post_title, wp_posts.post_date FROM wp_comments, wp_posts
where wp_comments.comment_post_id = wp_posts.ID
group by wp_comments.comment_post_id, wp_posts.post_title, wp_posts.post_date
order by commentcount desc

29th of February exists in WordPress (almost)

I discovered the other week that if you put an illegal post date into WordPress, such as 29-Feb-2006, it displays as the next day, 1-Mar-2006 on the page, but doesn’t allow commenting or going to the permalink, because in the database it’s still there as 29-Feb, so it doesn’t show up if you try to click through to it.

I suspect it’s just PHP’s date handlers being helpful, so it may show up in other PHP-based software.

Bloglines no like

The otherwise very fine Bloglines RSS aggregator isn’t liking this site very much, reporting errors when trying to add the Geekrant RSS feed which works so well for most other people.

Bloglines error

Uh, yes the feed does exist. Those who like XML can look at it raw.

It’s doing the same for some other blogs, including my personal one, having rejected it since late December. Very odd. And I’m not the only one.

I’ve contacted Bloglines support, so hopefully they’ll be looking into it.

WordPress 2.0 is coming soon

WordPress junkies may be interested to hear that the WordPress 2.0 Release Candidate is out, with the real release expected to be only days away. From the sounds of it there’s a heap of cool new features in it, though much of it is under-the-hood changes that will affect developers more than anybody else.

One of my summer holiday projects is to upgrade all my WordPress installations. I’ll take a look at 2.0, but of course I’m always wary of jumping straight into major new releases, especially since 1.5.2 is incredibly stable.

Seeing a new server before re-delegation

One of the weaknesses of WordPress and most other web-configured applications is that unless you want to go SQL or config-file-wrangling, it’s pretty much only configurable via the web, at least for tweaking, importing posts, setting up most of the options. This is a problem when, for instance, you’re migrating an existing site onto WP, and it’s on a new server, as you can’t get to the wp-admin screens.

The way to do it is to hack your hosts file. Once the new server is running and WP is setup on it, find your hosts file and add an entry to the new server. On Windows, this is the c:\windows\system32\drivers\etc\hosts file.

Chuck in a line that says contains your new server’s IP address, and the hostname. Something like:

192.168.0.1 www.evision.com.au

(Whoopsie, real-world example with a fake IP. The new evision site is going live Real Soon Now.)

Save, then away you go. You can see the new site and tweak to your heart’s content, but nobody else will be able to see any of it until you re-delegate.

The catch? It probably won’t work from behind corporate networks, where your computer uses a proxy.

WordPress’s best defence against the dark arts of spam

Scoble writes that WordPress.com has strong comment spam protection, but that it sometimes gets false positives.

I’ve found nothing better for spam protection than WP-Hashcash, which uses Javascript to make sure it’s a human entering the comment, not a robot, but without captchas or other stuff the user has to do. Works like a dream.

The only down side is it doesn’t work with some older WP templates. So while this site is fully spam equipped, my personal blog won’t run it until I upgrade the template (probably a project for Christmas time).

But apart from that, for WPers out there, I can’t recommend it highly enough.

Combined with settings that ensure firsttime posters go straight to moderation (subsequent postings are approved automatically) it ensures that those damn spammers never get their comments published on my site.

I might add that the company I work for (which develops B2B messaging systems) is working on a new site. To encourage them to update it regularly (some might call it blogging, but I’m emphasising “regular updates to existing and potential customers”) I’m building it on WordPress. Given WP’s ability to do a site of static pages and dated entries, it should work very well.