Feed on
Posts
Comments

Results for php

Revisiting “old” Code

Posted May 19th, 2010 by Steve

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.

Using the new Facebook Graph API off-line

Posted May 5th, 2010 by Steve

One of the features of the old Facebook API was “off-line” access – basically where you could interact with Facebook in a “non-interactive” way : in other words a program or script could interact with Facebook on your behalf without you having to have a Facebook window open in your browser.

The new API also supports this but the documentation is not really totally clear on the “process” needed to do it.

So I sat down and worked it out. The code you are about to see is not neat, or tidy. It contains no proper error handling or checking apart from the bare minimum needed to make it work.

Pre-requisites

You will need:

First of all we need to make sure that we have a table to store the session data in. We are actually storing all the session data : this might be overkill but as a lot of this is still undocumented I felt it was safer to store everything.

So at the start of our example lets do the dirty work with the database. If you were doing this properly you’d have this in a function which you called once, for example with a WordPress plugin you’d call it on plugin activation. But we’re not doing that here so …. and don’t forget to change those db_  parameters to match your system.

$db_server = "localhost";
$db_username = "dbuser";
$db_password = "dbpassword";
$db_name = "dbname";

# Lets connect to the Database and set up the table
mysql_connect($db_server,$db_username,$db_password);
mysql_select_db($db_name);
$ct_res = mysql_query("CREATE TABLE IF NOT EXISTS `facebook_user` (
   `session_key` VARCHAR( 80 ) NOT NULL ,
   `uid` VARCHAR( 80 ) NOT NULL ,
   `expires` VARCHAR( 80 ) NOT NULL ,
   `secret` VARCHAR( 80 ) NOT NULL ,
   `access_token` VARCHAR( 120 ) NOT NULL ,
   `sig` VARCHAR( 80 ) NOT NULL
   );"
);

OK So that’s the DB work done and each time we run the script it will create the table if its not there. Now we can set up the Facebook side of things. Don’t forget to change the path for the facebook.php file (which you did download  didn’t you?). You’ll also need the information about the Facebook Application you set up because I’m not letting you share mine! You may also want to review the permissions that are being granted – the ones in this code are the ones my Wordbooker application uses

# Now lets load the FB GRAPH API
require '../src/facebook.php';

// Create our Application instance.
global $facebook;
$facebook = new Facebook(array(
 'appId'  => '101001010101010101',
 'secret' => 'faafaffdfasdffsafsfsddfasd',
 'cookie' => false,
));

# Lets set up the permissions we need and set the login url in case we need it.
$par['req_perms'] = "publish_stream,
                    offline_access,
                    user_status,
                    read_stream,
                    email,
                    user_groups";
$loginUrl = $facebook->getLoginUrl($par);

The “heart” of the code is the get_check_session function. This function checks to see if we have a session stored in the database and if we do it returns it. If we don’t have a session but a session is being passed in via the URL it gets it, stores it and then returns it. If neither of these cases are true it returns nothing.

function get_check_session(){
  global $facebook;
  # This function basically checks for a stored session and if we have one returns it,
  #If we have no stored session then it gets one and stores it
  # OK lets go to the database and see if we have a session stored
  $sid=mysql_query("Select access_token from facebook_user");
  $session_id=mysql_fetch_row($sid);
  if (is_array($session_id)) {
    # We have a session ID so lets not get a new one
    # Put some session checking in here to make sure its valid
   try {
     $attachment =  array('access_token' => $session_id[0],);
     $ret_code=$facebook->api('/me', 'GET', $attachment);
    }
     catch (Exception $e) {
       # We don't have a good session so
       echo "woops";
      $res = mysql_query('delete from facebook_user where expires=0');
      return;
    }
  return $session_id[0];
 } 

 {
  # Are we coming back from a login with a session set?
  $session = $facebook->getSession();
  if (is_array($session)) {
   # Yes! so lets store it!
   $sql="insert into facebook_user (
               session_key,
               uid,
               expires,
               secret,
               access_token,
               sig)
             VALUES ('".$session['session_key']."','".
                        $session['uid']."','".
                        $session['expires']."','".
                        $session['secret'] ."','".
                        $session['access_token']."','".
                        $session['sig']."');";
   $res = mysql_query($sql);
   return $session['access_token'];
  }
 }
}

OK, believe it or not we are just about there with only a few more lines of code to go. Are you ready?

$access_token=get_check_session();
# If we've not got an access_token we need to login.
if ( is_null($access_token) ) {
echo '<a href="'. $loginUrl.'"><
img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif" alt="" /> ';
}
else {

# This is where you put your code.
$target=1010101010100110;
$attachment =  array(
 'access_token' => $access_token,
 'message' => 'Did a Test Post :',
 'name' => "Offline posting using stored tokens",
   'link' => "http://blogs.canalplan.org.uk/steve/2010/05/05/using-the-new-facebook-graph-api-off-line/",
  'description' => "This post was made using a stored access token",
  'picture'=>http://blogs.canalplan.org.uk/steve/files/2010/05/Screenshot-5-300x194.png",
			);

$ret_code=$facebook->api('/'.$target.'/feed', 'POST', $attachment);

echo "Returns : ";
var_dump($ret_code);
echo ""; 

$attachment =  array(
'access_token' => $access_token,
 'message' => "and this is a comment I've just made on the post using that same stored token",);

$ret_code=$facebook->api('/'.$ret_code['id'].'/comments', 'POST', $attachment);

echo "Returns : ";
var_dump($ret_code);
echo ""; 

}

Basically any code in the ELSE {} block is executed if you have a Facebook access_token. In the example what we do is post a message to a “target” which is a FB user ID (you can use names rather than numbers), and then we immediately comment on it. Which produces something like:

image showing FB wall postings

A Wall post and an associated comment made by the php code.

So there you go. Why not download the code and give it a go.

Hitting a moving Target

Posted April 28th, 2010 by Steve

Things move fast in the IT world:  Oracle spit out a new version of their database every couple of years, Microsoft keep…. well actually the less said about Microsoft the better to be honest, and as for Apple…… :roll:

I’ve been coding away on my Wordbooker Plugin since the tail end of last year. I had great plans for version 1.8.  I was going to add internationalisation and completely rebuild comment handling from the ground up as its not really working properly.. Hey I coded it in a day and bolted it onto the existing code so what else would you expect…

So I’d got all these plans worked out in my head and then along came Facebook and their developer conference (F8) who shoved a huge great spanner into the works.

Now for those who have never tried programming against the Facebook API you wont know just how annoying it is. It is rather like trying to nail jelly to the ceiling : Facebook quite happily change the API on the live site without telling anyone which breaks things. Go on.. how many times have you seen the “Oops, something seems to have gone wrong” message? Well developers get that too – or rather they get calls that suddenly return no data, or incorrect and incomplete data, or error codes they’ve never seen before.

People file bug reports and Facebook go and change the documentation and then deny its an error. Or Facebook fix the bug and everything is fine for a few weeks then it re-occurs which suggests a lack of a proper test and release process. The worst one I’ve seen is a bug which apparently “fixed” itself with Facebook representatives saying they did not know what had caused the problem or why it was now working again. The PHP files they provide don’t even have version IDs in them so you can’t tell if you’ve got the latest version, or worse still : you can’t determine the version of the files that another WordPress plugin might have installed – so your code doesn’t work because the version of the Facebook files they have installed doesn’t have the function, or class, you need for your code to work.

So any way, along comes F8 and a whole new way of interfacing with Facebook : The Graph API, and along with that came a new data model and a new data permissions dialogue, and a new Data policy. Everything new and shiny and the statement that “On June 1, 2010, we’ll automatically transition all Facebook Platform applications and websites who have not yet migrated.”

Sounds good doesn’t it. Apart from the fact that no-one at Facebook has explained how you can use the new Data permissions dialogue with the “old” API, and everything I’ve tried simply comes back with meaningless errors, and from what I’ve read other developers have experienced the same problems.

So I guess I could just convert my application over to the new API couldn’t I, that would make things easier wouldn’t it? Ahhh…………..actually I can’t because Facebook haven’t actually written the PHP API libraries yet – well not to the point of supporting “offline” access, which is what my application relies on. Actually that last bit says a lot about Facebook : They announce a whole new API and a whole new data structure, but the only way to access it is hand crafting your own CURL statements and running a “live” Facebook session. Talk about the right hand not knowing what the left is doing….

Madness

WordPress and Facebook Part five

Posted November 10th, 2009 by Steve

Well I’ve been hard at work on my forked version of the Wordbook plugin which links your own hosted WordPress Blog with your Facebook account. Oh and it also works with WordPress MU too.

Its now really reached a point where I’m quite happy with it.

So what does it now support?

Multiple Facebook account / WordPress account support

If you have multiple users of your blog the old version wouldn’t post to YOUR Facebook account. It would post to THEIRS, if they had set it up. This version of the plugin now handles multiple WP Accounts. If you as the blog owner only want it so that WP posts go to your FB account then go into the Options screen and set the default account to be yours, and that should be it, any person using a different WP account to post to your blog will publish those stories to your FB account.

But what if you’ve got a Family WordPress where different people would like to post to WP and to their OWN FB accounts. Simply get each of them to login to WP as themselves and configure WB as if they were the only user. Then when all of them have done this go back in as yourself and set the Default account to be you.

On the Edit Post page there is a WordBook Options block which includes a drop down list of the blog you wish to post to, if you want to post to your default blog then you don’t need to touch this but if someone wants to post that post to their FB account all they need to do is pick their name from the drop down list before they post.

Length of Extract

This allows you to change the length of the extract posted to Facebook. The minimum value is 200 and the maximum is 400 (at the moment) with the default being 256 characters. The extract will be trimmed to the nearest full word BELOW this value.

Default Publish Post to Facebook

This allows you to choose if posts should automatically be posted to Facebook. This option can be overridden from the Edit Post page

Post Attribute

This allows you to change the attribute line when posts are sent to Facebook. By default this is set to “Posted a new post on their blog”. This option can be overridden from the Edit Post page.

Republish Post if edited more than x days ago

This allows you to control how long it should be before Wordbook considers an edited post to be a “new” post and re-publishes it to Facebook.

Override Re-Publication window

This allows to to force all edits to be reposted to Facebook ignoring the republish window. This option can be overridden from the Edit Post page.

Update Facebook Status

If this option is checked then the title of your blog post and its permalink will be posted to your status, along with the text specified here. This can be overridden from the Edit Post page. NOTE: If this option is Selected then your status is ALWAYS updated, even if you choose NOT to publish your post to Facebook.

Import Comments from Facebook for Wordbook Posts

This version of Wordbook supports the importing of comments made on Facebook back into your WordPress blog. This allows you to set the default behaviour. This option can be overridden from the Edit Post page.

Auto Approve imported comments

If you trust your friends on Facebook then you’re probably quite happy for their comments to automatically get posted as comments on your WordPress blog. If this option is not set then any imported comments are held in the moderation queue.

Posting using XMLRPC clients

Posts published to your WordPress account using XMLRPC clients will now also publish to Facebook – if the default option of posting to Facebook is set. Posts made via this method will also pick up the default target Facebook account, the default post attribute line, and the Update Status options.


Upgrading from the stock version obtained from the WordPress plugins repository:

* You need to de-activate the old plug in first.
* Then DELETE the wordbook folder from wp-content/plugins and then upload the new version. DON’T just copy the new files up.
* Re-activate the plugin
* Go to the Options page for the plugin and you can set all the new wizzy options. If you want to pull comments from your Facebook account you’ll need to grant the plugin permission to read from your stream. If you don’t grant this permission then you can’t pull comments, and I’ve no idea what my code will do if it tries to do that because I didn’t test it! So you have been warned!

Debugging

The only place I’ve put any real debugging in is in the cron job code because its very hard to actually work out if its working if there are no comments to pull. Debugging for that can be enabled by editing two lines in wordbook_cron.php:

define (’DEBUG’, false); which you change to true

and

$debug_file=’/tmp/wordbook_’.$table_prefix.’debug’; which you may need to change if you want to change the output directory.

So where is it I here you ask?

Right Here:

wordbook1.5

Posting to WordPress MU by Email Part 2

Posted October 20th, 2009 by Steve

Warning: This post contains material of a technical nature, if you start reading and feel dizzy or nauseous then stop reading immediately and go and lie down.

This is a follow up to my previous post where I outlined a prototype of an extension for WPMU which allowed posting to multiple blogs from one centralised POP3 account which collected all posts from all users of all blogs. This is very different from the usual way of doing it where you either go out to get the emails from external email addresses or you have multiple local accounts.

Well the prototype has, like Frankenstein’s Monster, come alive and it’s now got configuration screens and lots of rich techy goodness to it.

I’m not going to go over the instructions on how to configure the MTA again, those are documented on my last post, and in the notes in the downloadable archive :

Post by Email Post by Email-v1.zip

The Archive also contains instructions on where the TWO files need to be placed for the system to work.

What I’m going to cover here is the new features that I’ve added since the last post. Yes I have way too much time on my hands, but this is keeping my brain sharp so its all good at the end of the day.

These can be broken down into to distinct groups which are reflected in the two new options that will appear on the Settings menu:

Blog Level Options

These are options which are set by the blog administrator or blog owner:

Default Category for posts : This is a drop down of all categories and you select one to be the default category for posts without a category override

Optional Categories: This is a tick box list of all other categories in your blog, Toggle the ones you want users to be able to use in their category override.

Allow Posting By:  This is a tick box list of all the user who are members of your blog. Toggle the ones you want to be able to use the post by email. This will include YOUR address and by default no-one of them are checked (which basically deactivates the system for your specific blog).

User Level Options

These are options which are set on a user by user basis.

Personal Identifier : This is a optional text string which allows users to “secure” their posts. If this has been set then posts from them will be rejected outright. So set this to something good but memorable as you’ll have to provide it for each post.

Alternative Email: This allows you to nominate a secondary email address which the system will accept emails from. If you do not set this then posts will only be accepted from the email address registered to your account.

Additional Posting options

To support the “new” features there are now some additional posting options which you set at the top of your email.

wppbm-categories: A comma separated list of category names for this post. NOTE: This is names not numbers which makes it easier to remember (or are you so sad that you know the underlying IDs of your categories). You’ll find a list of the available categories on your user settings page. So assuming that the Administrator has enabled them you could do something like: wppbm-categories : computing,witterings which would post your post with those categories. If you do not specify this line then the default category set by the Administrator will be applied.

wppbm-pid: Your PID. If you’ve set your PID then you have to provide it here. If you’ve set it and don’t include it (or get it wrong) then your post is toast!

So that’s basically it. I’ve created a dedicated Post by Email Page where I’ll always list the current version and the bug fixes/enhancements.

So download it, configure it and play with it and bounce bugs back to me as comments!

Posting to WordPress MU by email

Posted October 7th, 2009 by Steve

Warning: This post contains material of a technical nature, if you start reading and feel dizzy or nauseous then stop reading immediately and go and lie down.

NOTE: The code and some of the details in this article have been superseded by a later post

There are a lot of clients for the PC/Mac/Linux which allow you to post to your WordPress blog without having to log into the back end, and some might question the need to be able to send posts into your blog via email but there are several situations where you can’t use a fat client or you don’t want to use the web back end for various reasons

WordPress MU (the multi-user/multi-blog version of WordPress) supports a basic post by email feature but it involves each user setting up their account to go out to an external email address and picking up the email. This seems rather “backwards” as it means your WPMU server is having to go out to find your new posts, and if you’ve got a lot of blogs then that’s potentially a lot of outgoing POP3 requests and it means that your have got the email account and passwords for your users, which some might see as not being a very good idea. WPMU suggest using a specific account to support posting by email and keeping the account “secret”.

Surely it makes sense for the posts to be delivered to the WPMU server and processed there. This has several advantages when you think about it.

So I’ve written a new version which uses a local virtual domain and a single pop3 box.

So the user emails theirwpmuloginid@some.domain.here which ends up in a pop3 mail box on a server somewhere (preferably the same server as WPMU). Every email sent to some.domain.here arrives into one single pop3 mail box rather than being in different ones. This “catch all” account means that you don’t have to do anything clever like creating email accounts for each user as they sign up.

My process then opens that pop3 account and reads each email in turn.

It will only post if the sender email ID matches the username it is associated with (from the user table). So you have to send email from the email address you signed up with, or the email address you’ve set it to in your account settings and you have to send it to the username you use to login to the site as. This is only very basic security and I will be adding more but for the first pass of the code I felt that this was good enough to prove the principle.

So apart from allowing me to post to my blog via email what else does this “extension” provide? Well users can specify some “options” in the email which affect how their post is handled:

There are currently 4 options that they can provide:

wppbm-tags: comma separated list of tags for this post
wppbm-status: publish [default] | draft | pending
wppbm-type: post [default] | page
wppbm-comments: open [default] | closed

All of these options are optional, you do not have to provide them and if you don’t provide them then the defaults indicated will apply. WPMU developers who have played with the wp_insert_post function will probably recognise them.

Posts accepted by email will be assigned to the default category for new posts.

It currently accepts basic html marked up (bold, italic, underline) messages (either manually coded or from the rich text editor in Google mail). Yahoo marks its html messages up differently so its not working if you try to use their Rich Text Editor, and “advanced” html mark up (like font sizes etc.) don’t work from Googlemail either. Again this will be addressed in a future release.

Things that need adding are:

  • A PID field (so that people can’t just “fake” the sender email address).
  • Ability to support posting to different blogs (rather than just primary).
  • Ability to support posting from more than one email account.

So if people want to try it, and leave feedback then this is how you implement it. If you can’t edit your Postfix configuration (or don’t know how to) then I’m sorry but I can’t help you. I don’t know if other MTAs support virtual domains but if they do and you get it working then we can add those instructions.

I’ve only tested this on Linux so you’ve been warned!!!

In these instructions I’m using posts.my-dummy.domain to represent the domain we’ll be using to send emails to.

Step 1 : DNS Records
Configure your DNS records to support posts.my-dummy.domain. You need to be able to send email to this domain.

Step 2 : Create a REAL email account on your server.
However you do it you need a local email account on the server that you’ll be directing email to. In this example I’m going to call this user wpmuposts

Step 3 : Postfix Configuration
Edit your postfix main.cf file and add the following two lines:

virtual_alias_domains = posts.my-dummy.domain
virtual_alias_maps=hash:/etc/postfix/virtual

NOTE: The virtual_alias_domain MUST NOT be listed in the mydestinations configuration parameter.

Create/edit the /etc/postfix/virtual file and add the following line :

@posts.my-dummy.domain wpmuposts

Save the file, and then you need to create a hash for it using the postmap command. I do this by going to the postfix directory (/etc/postfix on my server) and typing:

postmap virtual

You may then wish to check that everything works by waiting for your DNS to propogate and then going to an external email client and sending an email to anything-here@my-dummy.domain.

You should end up with an email sitting in the POP3 email box wpmuposts. If not then you need to review your settings. There is no point in going beyond this point unless you’ve got the “catch all” email working.

OK so email is now working. That really was the hard part. The rest is pretty easy, and if you’re doing this then going in and editing a php file isn’t the sort of thing that scares you right?

Step 4 : Getting and configuring the extension

Grab a copy of post_by_mail.php and save it to your computer.

Open the file in your favourite text editor and look for the following :

// USER NEEDS TO SET THESE.
// Postfix will need configuring to support virtual domains with a wildcard to deliver to the account given below.
define ("POP3HOST","your host here");
define ("POP3PORT","110");
define ("POP3USER","special pop3 user account here");
define ("POP3PASS","special pop3 user password here");
///

and edit them to match the POP3 settings you need to access your special POP3 email account: So for example:

// USER NEEDS TO SET THESE.
// Postfix will need configuring to support virtual domains with a wildcard to deliver to the account given below.
define ("POP3HOST","localhost");
define ("POP3PORT","110");
define ("POP3USER","wpmuposts");
define ("POP3PASS","notarealpassword");
///

Save the file and then upload it to the ROOT of your WPMU installation. DON’T FORGET TO REMOVE the .TXT extension!

That’s basically it, the extension is there. If you want to give it a different name, for security reasons, then feel free to.

To test it, send an email (and I’d suggest setting the wppbm-status to draft) to yourwpmulogon@posts.my-dummy.domain. Then once its arrived call:

http://my-wp.domain.here/posts_by_mail.php

You should see some diagnostic message on the screen and hopefully, fingers crossed, you’ll end up with a new post in your blog.

So all you then need to do is set up a cron job. At the moment you can’t use the PHP CLI to run this code but you can set up a cron job to to a wget on the URL. As this isn’t a silent process I don’t recommend putting a call to it into your themes, its much better to keep it controlled by cron (and that way you can route the output to a log file to keep an eye on it).

Debugging
If you think that there are problems and you want to keep checking the same email as you add debug code to the extension then you’ll want to stop it deleting emails / posting messages.

To stop it posting into your blog look for the following line (line 241):

$post_ID = wp_insert_post($post_data);

and put a # in front of it.

To stop it deleting messages on completion look for the following code (line 256 – 262):

if(!$pop3->delete($i)) {
echo ' <p>' . sprintf(__('Oops: %s'), esc_html($pop3->ERROR)) . ' </p>';
$pop3->reset();
exit;
} else {
echo ' <p>' . sprintf(__('Mission complete. Message <strong>%s</strong> deleted.'), $i) . ' </p >';
}

and comment it out.

So there you go. Please remember that is a work in progress and support for complex HTML isn’t there and you install it at your own risk. If you’ve got any suggestions on improvements, or you’ve found a bug then please let me know.

WordPress and Facebook – Part 3

Posted August 11th, 2009 by Steve

I posted previously about the Wordbook plugin for WordPress which links your WordPress blog to your Facebook account. I’d down loaded it and installed it and it worked quite well.

Then I wrote about how it reposted WordPress posts if you edited them. It only did this if they were more than a day old which seemed a bit odd. So I changed the code to stop it doing that.

Also I wanted to have a link back from my blog to my Facebook account so I wrote a very minimal sidebar widget to link the two together.

This morning I’ve been recoding the widget so that its more flexible

So my widget now supports:

  • Widget title can be changed by the user, it’s no longer fixed as Facebook Status
  • User can override the name displayed – so rather than using the name on Facebook you can display a different one. On Facebook my name is shown as Stephen, but if I want on my widget that could be replaced by “Steve” or Wombat, or anything!
  • Different Date Formats. You can now select from a choice of date formats including a Facebook style textual one.

I might add some more formatting options such as changing the style of the status (currently fixed as italic).

To make sure that the widget and the plugin don’t get separated I’d coded my widget into the end of the plugin code and some people on the Wordbook group on Facebook have cut and pasted in to their copies of the plugin and it all seems to work.

But now my widget code is up to 179 or so lines and its getting a bit much to ask people to cut and paste it into their code. So I guess once I’ve got it tidied up a bit I’ll need to contact the developers of the plugin and get my code merged into the code base over on the WordPress plugins site.

Or if you want to try it now then follow these easy steps:

  1. Download the widget code :wb_widget.php
  2. Save the file into the wordbook directory under your plugins folder. Ensure you save/rename the file as wb_widget.php
  3. Edit the main wordbook.php file and add the following line immediately preceding the closing ?> tag at the end of the file: include(“wb_widget.php”);

This also means that when I add features to the widget you just need to grab the latest version from here.

Pub Night

Posted January 20th, 2009 by Steve

Pub Night is a website that I set up for a group of friends who go out drinking once a week in Cheltenham. We’ve been doing it for years and a few years ago now Nick and I came up with the idea of building a website for it. I went for a Wiki based site but because we wanted “standard” information for each pub I built a rather large extension for it which basically allows us to use Data pages to hold the information on the pub and then for each pub we have a simple page which contains some tags which allow us to display the information in a controlled format.

Pub Night is primarily based in Cheltenham but has details on some pubs outside of the town, primarily in GloucesterLondonUpton upon Severn and Market Drayton.

There is also a sub group of Pub Night called Out Of Town Pub Night Group (or OOTPNG for short) which once a month goes to a good pub within a reasonable driving distance of town. The venues and drivers and approximate dates had been decided and I went to load them into the system so I could put up a page with the 2009 locations. That is where the problems began. The code that drives pub night talks directly to the database behind the wiki which means that information on pubs normally comes out in the order the pubs were added into the database. To support the new page I added two new fields to the data set – nextvisit and driver. But I wanted to sort the information on the nextdate. So I’ve had to go in a recode how the “where” part of the extension works so that rather than just trawling through the pubs in turn and if they match the criteria displaying the information I now go through the pubs once and grab a “sort” field from the data (if specified) and then I sort the list of pubs on that and then process each one in turn to get the information. Sounds easy doesn’t it?

Well it is when you are dealing with text fields because you can simply build the array with the Digraph and the “sort” field and then use the php functions asort and arsort. Date fields are another matter entirely. Pub Night stores its dates in dd/mm/yyyy format which do not sort. PHP has a strtotime function which converts “human” date formats into unix timestamps. Those we can sort easily so problem solved. Afraid not because strtotime doesn’t like dd/mm/yyyy. So I had to us the php mktime function to parse the PN date format into something I could then pass into strtotime to get the timestamp and now its all working.

Now all I have to do is fix the problem with null dates which upset it (silently, they just spew errors into the error log!)

Can there be too many Online Fora?

Posted April 2nd, 2007 by Steve

Over the weekend, when I was moving the boat, I was sitting on the back deck thinking about a lot of things. Camsigh has gone quiet over the past couple of years, and other boards that I’m signed up to such as Ghostly Stay , PhantomFest and Café Phoenixx all seem to have similar cycles – a flurry of postings and then it all goes quiet for a bit, then some more come along and then it goes quiet again.

So why should this be? Is it part of the normal cycle that forums go through or is there something else happening?

I think its the latter – When I set Camsigh up back in January 2004 the only way to get a forum was to either pay for one or run your own server (either from a hosting company or if you were really sad – yourself) and run a forum on there.

Then along came proboards, myfreeforums etc. etc. and the “free” forums phenomena took off. Running costs are recovered through the placing of adverts (over which you have no control) but in return for that you get a good uptime, a responsive server and it would seem some pretty good anti-spam measures.

So now there is a forum for everything – a forum for bunion sufferers, a forum for people who collect pictures of buses, a forum for every conspiracy you could ever imagine (and then a few more). The list goes on and on, it is endless. The Internet is full of forums.

But something is going on with these free forums. Running this site and doing admin on a few others there is a rising level of spam advertising forums (hosted on various free forum sites). These forums aren’t real forums – they contain nothing but a URL redirect to another site which will then try to sell you dodgy drugs, iffy insurance, or manky mortgages. These sites bring no money into the coffers of the companies hosting the forums and give the scam merchants yet another marketing vector. Sooner or later the free forum hosters will have to clamp down on the processes needed to create a forum and put more stringent controls in to stop their services from being abused.

Of course the spammers are well ahead of the game – they are now spamming free Blog services which they using in a similar way to the way they abuse forums.

So who knows what will happen – maybe a couple of free forum providers will go down the tubes, maybe users of the forums will get sick and fed up of the continual stream of spam being forced down their throats.

The Web should be a great place for people to learn, to communicate, to share. But the problem is that the spammers just don’t give a shit : they don’t care who they annoy, who they abuse, who they peddle their shit to. They have no morals at all – I’m sure they spam cancer support forums and such like with their odious filth.

Of course the spammers are just doing what they have been paid to do. At the end of the day its people like Visa and MasterCard who could put a stop to a lot of it. If they refused to do business with companies who spam or who deal in products like “Generic” counterfeit drugs then the money flow would stop. Mind you it would stop if people out there actually stopped believing the crap they are being spammed with.

Playing around with PHP and PHPBB

Posted February 8th, 2007 by Steve

I’d been looking round for quite a bit for a nice acronym explainer for PHPBB… I found quite a few but none of them did what I wanted.

So I took a couple of existing mods and hacked them round a bit and have produced just what I wanted:

1) Centrally maintained definitions
2) Proper formatting of definitions (i,e, full phpbb code)
3) Nice sized pop up when you move over the word/phrase
4) Word/Phrase is also a link to a post containing the definition.

OK maybe other people will think its rubbish.. but I like it ;)

Google Ads

Posted September 30th, 2006 by Steve

Well I’m quite pleased with myself. The mod to support google ads in the phpbb forums only handles text ads. I wanted to put in some of the referrer ads so I wrote a little bit of php code which sets up an array with the different ads in and then picks one at Random.

I also dropped the code to put random Google “Pack” adverts into this blog mod which works quite well ;)

Phew!

Posted September 24th, 2006 by Steve

Well the e-commerce site is up and running at www.ladykat.co.uk

I’ve been working on a rather large silly project to “recover” some old phpbb forum posts from html file dumps. It was hard work but fun.. the fruits of that effort can be found at www.tty.homelinux.org/board

I’m also working on a two stack parser in PHP – so far I’ve got all the logic worked out and I’ve written the extression parser which breaks the inputted line into chunks. Not sure when its going to go live but when it does pubnight ( www.pubnight.org.uk ) is going to get a lot more dynamic content.

Gone away!!

Posted July 18th, 2006 by Steve

Well after following the instructions here http://www.gotroot.com/tiki-view_blog_post.php?blogId=2&postId=34

I’ve managed to get it so that spammers on my boards get a 403 message.

The only thing I found was that the directives had to go into the apache2 config file rather than the .htaccess file which complained “order not allowed here”. I also adjusted it so that only POST is blocked..

I’m going to run with it for a few days then I’m going to add a couple more RBLs to the list and then I can hopefully put the trackback link back in.

And for those who dont want to down load the whole of the apache source files just to compile this one little bit here is the recompiled mod_access for Apache 2.0.48

http://www.tty.homelinux.org/board/mod_access.zip

Things

Posted August 19th, 2005 by Steve

Its lunch time – I’m sitting here watching the horses canter round the field and I can see a small group of tourists walking along the top of the Malvern Hills.

Its so much quieter here than in the Birmingham Business Park, the scenery is much better too, and there are several good pubs within a short commute.

So apart from work what have I been doing? Not doing the kitchen renovations if you must know – the disaster that is the window (Thanks a bunch Cheltenham Council for using jerry builders to build the Priors Farm estate) really is a big disincentive. I’ve also been doing some coding on an extension to CanalPlan which should implement social networking, blogging and “tracking”. OK its not going to do all of that to start off with but…

Of course this means me learning how to handle sessions in PHP and interfacing PHP with a Database. Still its all good fun (!).

Server uptime: 79 day(s), 23 hour(s) and 18 minute(s) | Server Load: 0.58, 0.20, 0.11