Revisiting “old” Code
Nick commented once about some of the code in CanalPlan AC and how it was suffering from “bit rot”. Basically code that you shoved in, often as a quick dirty fix and then it starts to fail but with no good reason.
Well Wordbooker is suffering from bit rot, its just that luckily no-one has noticed it yet, well apart from me that is.
Wordbooker took code written by Robert Tsai for his plugin (Wordbook) and extended it. That is why Wordbooker is called Wordbooker – because it stands for WordbookE[xtended]R[elease]. Robert’s code used to support the WordPress PHP libraries for PHP4 and PHP5. PHP4 support was dropped but the wrappers were left inside the code, adding a level of abstraction around the calls to the Facebook PHP libraries.
When I added all the new features such as posting to walls and FB widgets and so on, into his code I sometimes used his wrappers and sometimes made the calls directly.
Facebook then depreciated some functionality and so calls to functions supporting that got commented out and eventually I stripped most of the code out.
I’d added functionality to handle comments really as a sort of proof of concept and then I added posting support to pages, but comments to pages didn’t get processed properly due to slight differences inside FB on how pages are handled.
So that was the next big project – re-write comment handling to make it a lot more robust (and at the same time simpler).
But then Facebook came along with the Graph API and the Oauth authentication process and said that all applications would be force migrated to the new Authentication method on June 1st. The new Graph API would make my job simpler as I only use a few calls (post to wall, post comment, get comment, get status, and a few FQL calls) and so obviously I should think about moving my code to use it.
That wouldn’t be bad if the Graph API was complete and not riddled with bugs (for example if you include a link in a post it thinks you are doing a “share” style post and goes and scrapes that URL – something which is not right and not how the old API works), but as it is I can’t use the new API for anything but authentication, so I’ve had to work out how to use the Oauth method for signing on, but then use the old API for the rest of my code, all under the looming date of the end of the month and with me working a day job as well.
Facebook also changed their policy on posting to walls and I asked them for clarification, and they asked for more information which I’ve given them, and now I’m waiting to hear back from them. It could mean that I have to change my code, but actually it will make the process easier to code and make it easier for the user to understand, so I am going to make the changes any way.
WordPress is also changing – with 3.0 coming out really soon now – and I wanted to make my install more multiblog friendly : so 4 tables per WP install rather than 4 tables per blog which means some quite jolly logic to work out if you are in WP2 (or WPMU2) or WP3 (running in single or multiple blog mode)
So I’m revisiting my old code and wondering if I should really throw 80% of it away and strip away the crud and spaghetti that seems to have collected during my rapid development of the project. I’ve now got a much clearer idea of how things should work and how the code should flow, and how to code round the countless “failures” of the FB back end which occur at depressingly frequently intervals, some of which I did last night when a couple of users were basically stuck because FB were playing round with code on the live servers again.
May 20th, 2010 at 8:51 am
So is 1.7.9 the result of this? I ask because I noticed a new version was available thru the dashboard and I upgraded this a.m. while fighting insomnia lol!
I was looking to find out what had changed and found this post.
May 20th, 2010 at 11:39 am
1..9 (or it might morph into 2.0) will be the result.
1.7.9 fixed some minor bugs and is really a wrap up before 1.8 (Oauth) comes out early next week.
May 22nd, 2010 at 5:40 pm
Hi Steve,
I’ve been using Wordbook for a while, I even got Rob Tsai to add some code to support WPG2 tags for images. I like the idea of cross-posting comments and I like that you’re taking his code and running with it!
I’ll wait until you’ve got Oauth all figured out before I switch over, but it sounds like you’re putting in a lot of work. From someone in the peanut gallery: “thanks!”
Can I encourage you to recognize and support WPG2 tags as image identifiers? The code I added can be found by searching the latest wordbook.php for “wpg2″. I’ve also added it here:
function wordbook_fbclient_publishaction(…) {
…
/* Pull out image tags. */
$wpg2_g2path = get_option(‘wpg2_g2paths’);
if ($wpg2_g2path) {
$g2embeduri = $wpg2_g2path['g2_embeduri'];
if ($g2embeduri) {
preg_match_all(‘/(.*?) $g2embeduri
. ‘?g2_view=’
. ‘core.DownloadItem’
. “&g2_itemId=$wpgtag”,
‘href’ => $post_link,
);
}
}
}
}
Thanks much,
Will
May 23rd, 2010 at 1:09 am
As I actually scrape the parsed post (i.e. a copy of what is posted to the browser) for images, rather than the stored text it might not actually need this. I’ve never used WPG2 as its not WPMU2 compatible as far as I’m aware and my primary dev environment is WPMU.