Tuesday, 8 January 2013

Tweaking a Drupal 7 user profile page

Sometimes (ok, often) doing something programmatically in Drupal 7 is like drawing blood from a stone. I wanted to replace the username with the user's real name as the title on all user profile pages. After much Googling (other search engines are available), I worked out how to do it.

Add the following to your chosen theme's template.php file - and assuming you've created an additional field in your user records called "field_profile_realname"...
function [yourthemname]_preprocess_page(&$variables) {
  $arg = arg();
  if ($arg[0] == 'user' && is_numeric($arg[1]) && empty($arg[2])) {
    # we're looking at a user profile page
    $user_data = user_load($arg[1]);
    if (isset($user_data->field_profile_realname['und']['0']['value'])) {
      $variables['title'] = $user_data->field_profile_realname['und']['0']['value'];

Friday, 13 April 2012

Speed Awareness

I attended my first (and hopefully last) Speed Awareness course yesterday evening in Milton Keynes. This AA Drivetech course was run by an ex- long serving Thames Valley police officer who had 20-odd years experience as a traffic officer and therefore knew what he was talking about.

There were 28 of us, split into groups of 4. There were a few group activities but what made the whole course more interesting was the use of keypads so we could "vote" for answers to various questions, some based on the Highway Code (how long since you read a copy?) and some on observation. It was obvious that quite a few of us were oblivious to some regulations, quite possibly since they had been introduced since we passed our driving tests. For example, did you know the speed limits for vehicles over 2 tonnes are lower in both national speed limit zones and on dual carriageways than for cars and motorbikes; and different again for lorries over 7.5 tonnes; and different yet again if towing?


At the beginning it was obvious that some people weren't happy to be there at all (be careful because you are expected to "engage") but by the end I think all but one were grateful for the education.

The tutor came up with all sorts of interesting stuff, including an argument against the perception that speed cameras are only there to make money. Based on the Thames Valley area, which has nearly 300 fixed cameras, only around 10% of them are active at any one time (so the 50% of attendees who were caught by one were described as "very unlucky"!). At the same time, most speeding occurs on motorways - yet the vast majority of Gatsos are on urban roads (since they tend to be installed where serious injuries or fatalities have already occurred). His argument was that if speed cameras were a run as commercial concern, surely every camera would be active and all the cameras would be on motorways instead?

You only get one chance in three years to attend these courses, but if given the choice, I would encourage anyone to take it. The Government very nearly closed the scheme (I presume to save money) but its been shown that the re-offence rate from attendees is something like 1-in-12, compared to points-takers who are 1-in-4 likely to re-offend. By doing the course, you avoid points on your license (although the fee is likely to be slightly higher than the fine) and you are not legally obliged to tell your insurer. However, they can ask you if you've been on the course and you are legally obliged to tell the truth - some insurers regard it as education and may lower your premium - some may not.

Wednesday, 11 January 2012

Charlie don't surf - yet

"Nicholas Negroponte, the brains behind the One Laptop Per Child initiative, is detailing a new plan to inspire the world’s poorest children to teach themselves to read using tablet computers.

Negroponte said that within a year his team would be dropping tablets into remote villages by helicopter – without staff – and letting children teach themselves how to use them.

Sorry but I can't help thinking of Wagner being played through loudspeakers and some Yank shouting "Charlie don't surf - yet".


Monday, 9 January 2012

YouTube RSS feed

The URL for an RSS feed from your YouTube channel is:

Why YouTube make it impossible to find that I don't know.

Sunday, 6 November 2011

"Witness" to M25 Accident

With the news of the M5 pile-up fresh in my mind, on the way home from Brands Hatch last night I was witness to the resulting carnage, not the actual event, of what initially looked like quite a serious accident on the M25. Transit and trailer both on their sides, lanes 2 & 3 blocked, Armco levelled for about 100 yards and two lamp posts knocked over - one into the other carriageway. I was the only person not involved who actually stopped - everyone else casually drove round the wreckage and disappeared into the night.

I checked first to see if anyone was trapped or injured - fortunately not - and dialled 999. We ended up with five fire engines, an incident support unit, two police cars and an ambulance. And they shut the M25 in both directions. All this on bonfire night.

As I didn't witness the actual event, the police didn't want contact details, but Essex Police did actually ring me back later.

Out of interest, there are eight points listed in the Highway Code are as to what you should do:
* Turn on your hazard lights to warn approaching traffic of potential danger [I keep a reflective jacket in the car too].
* Make sure other drivers switch off their engines and extinguish cigarettes for fire safety reasons.
* Call the emergency services yourself or get someone else to do so. Give full details of the location of the accident and any casualties. The operator will advise you on what to do before the services arrive.
* Make sure that any uninjured passengers move to safety, away from their own vehicle and passing traffic [the hard shoulder should be a safe haven, but unfortunately some drivers think that if the road is blocked, the emergency lane is for them].
* Leave anyone with injuries where they are – you could do more harm than good – except if they are in danger from fire or explosion.
* Do not take off a motorcyclist's helmet unless you have no option. Again you could cause serious injury.
* Give First Aid if needed.
* Wait until the emergency services arrive.

Monday, 17 October 2011

Line breaks in Drupal

If you're tearing your hair out trying to make Drupal keep line breaks and new paragraphs in the body of your Posts, Stories, etc. make sure Drupal itself isn't filtering out your <p> and <br /> tags.

* Go to Administer > Site configuration > Input formats
* For each one that you're using, in the Operations column click Configure
* Click Configure in the title line menu
* Go down to the Allowed HTML tags box and add the tags <p> and <br />

If you don't do this, even though your chosen WYSIWYG editor will happily add tags to your text, and even save them in the database, but Dupal will then filter them out again when displaying the page.

Wednesday, 25 May 2011

QuickTime Player 7

Perhaps Apple have realised the new QuickTime player that comes with Snow Leopard is pants because they provide, on the Snow Leopard install DVD, a version of the old player. Follow this URL to find out how to install it:


If you're installing Snow Leopard as an upgrade, it will retain your QuickTime Pro license key.

Snow Leopard Sucks

The more I use Snow Leopard the more I come to realise that its a lesson in how to abandon over 15 years of development of useful, easy-to-use software that people actually want to use in favour of something that might be prettier but is actually vastly more complex but yet with reduced functionality and a horrendous user interface. I have to wonder what's happened to all the designers and developers at Apple who actually knew what they were doing?

Friday, 11 February 2011

Its alright - we know where you've been...

These are the permissions you are expected to grant to Yahoo just so that your Flickr images can automatically be posted to your Facebook account. Sorry but I really don't think you need to know any of my information, let alone my friends' information.

Friday, 5 November 2010

Apache websever configuration

In configuring Apache to allow various directives in an .htaccess file, if you find yourself banging your head against a wall since you have used:

AllowOverride All

...and some directives still are not accepted, its because this line doesn't actually allow everything - to do that you need to use:

AllowOverride AuthConfig FileInfo Indexes Limit Options=All,MultiViews

Obviously the more things you allow, the less secure your server...

Friday, 8 October 2010

JW Player API

Thanks, authors of JW Player, for wasting at least 3 hours of my life because you have changed your JavaScript API and not published any documentation for it!

Quoting an entry buried in the help forum:

The v4 [and v5] player uses a completely different API, details here: http://code.longtailvideo.com/trac/wiki/FlashAPI

Sadly, that URL doesn't work. Now I expect Open Source software to have either completely useless, or just plain absent documentation, but we (and a great many others) have paid for this player - so its not acceptable.

Friday, 19 February 2010

Build a menu bar on-the-fly with JavaScript

Its not necessary to use either PHP or SHTML to include a dynamic menubar in a set of web pages - you can do it with JavaScript.

First define arrays containing all the links and the link text you want for the links - make certain the two arrays have the same number of elements!

Then have a loop that goes through these arrays, displaying them on the screen in order. You can do a bit of string testing to work out what page you're on and have that link displayed differently - perhaps in bold or just not underlined. Output all the HTML using document.write

Here's an example:

var textArray=new Array('home','news','people','places','views', 'faq');
var linksArray=new Array('index.html','news.html','people.html','places.html','views.html','faq.html');

for (i=0;i < textArray.length; i++) {
var str = window.location.toString();
var urlbits = str.split('/');
if (urlbits[urlbits.length-1]!=linksArray[i]) {
} else {
if (i!=textArray.length-1) document.write(' | ');

Note how the last line in the loop misses off the delimiter for the last item.

Save this JavaScript in a separate file - something like menubar.js - and include it in the same place in all of your HTML pages using a conventional link to an external JavaScript file:

<script type="text/javascript" src="menubar.js"></script>

My links here are just straightforward links, but they could equally be styled bullet list items, buttons, images, whatever.

Thursday, 18 February 2010

Parsing RSS with Dubin Core using PHP5

With the built-in XML functions of PHP5, its now pretty straightforward to parse well-formed RSS data, eg:

$link = $node->getElementsByTagName('link')->item(0)->nodeValue;

But when using getElementsByName you run into problems if you want to grab data in Dublin Core fields - this won't work:

$creator = $node->getElementsByTagName('dc:creator')->item(0)->nodeValue;

To solve this you have to use the getElementsByTagNameNS function and declare the namespace you are using - obviously in this case Dublin Core:

$creator = $node->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/','creator')->item(0)->nodeValue;