Drupal Logo

Drupal Private File Downloads With Public Files Access Set

16th August 2010 - 3 minutes read time

Drupal has two ways in which to allow users to download files, these are private and public.

With public the files are open for anyone to download and Drupal is not involved in the download process. This means that no statistics are recorded or permissions used when downloading the file. Each file is referenced by name.

Private file access means that Drupal is run every time a file is downloaded. This allows the download to be recorded and a permissions check run to make sure that the user in question is allowed to access the file. Each file is referenced by a path that can be completely different from the original filename.

WordPress Logo

WordCampUK 2010: A Review

21st July 2010 - 27 minutes read time

WordCampUK is an informal 2 day conference and barcamp that centers around using, working with and developing in WordPress. This year's WordCampUK was held in Manchester and so being local I could hardly miss the opportunity to attend. It was a great event, with great talks and lots of friendly people who were really enthusiastic about WordPress.

Drupal Logo

Drupal hook_form_alter() On Node Form

19th July 2010 - 2 minutes read time

I just spend the last few minutes looking for the solution to this so I thought that someone else might be able to benefit from it.

Calling the hook_form_alter() hook in your module using just the module name allows you to target all forms in your system, if that's the sort of thing you want to do. For a module called "My Module" this would be called mymodule_form_alter().

The power of hook_form_alter() hook is that it alos allows you to specifically target a form with a specific name within a module. A good example is if you want to alter the search form to add a class, which is a common task. To do this, create a module so that you can add the hook_form_alter() hook to it and then construct the function name in the following way:

WordPress Logo

Custom Post Types In WordPress 3.0

12th July 2010 - 32 minutes read time

This article relates to WordPress 3.0. Much of the code posted here won't work on previous versions and some of the information may change in newer versions.

WordPress already comes with five different content types built into the system.


This is the standard content type and is generally the most used in a blog install. Posts tend to be aggregated onto pages but this is not always the case.


This is a static content type and is used to display non-aggregated pages.


Every time you upload a file through WordPress it will store a record of it in this area. You can see this list of files by going to the Media menu item in your admin area. This is what is used when you click on the Media Libray tab on the Add and Image dialog in the edit post screen.


PHP Logo

PHP Version Number

25th June 2010 - 3 minutes read time

Different functions and options are always being added to PHP. Although new versions generally don't create much backward compatibility issues it is usually prudent to write production code that you know will work on servers running a slightly older version of the language.

To check the currently used PHP version you can use the function phpversion() or the constant PHP_VERSION. Both the function and the constant return a string that contains the version number. There are a couple of ways in which this information can be used, the first is to take the string and convert into an array using the explode() function. With this array you can then check the minor version number and run code like the following:

WordPress Logo

Wordpress Category Post List

24th June 2010 - 3 minutes read time

A friend of mine asked me to write a Wordpress function the other day that printed out a list of categories and any posts in those categories, along with any meta data that might be in the post.

All the function does is to get a list of categories and then for each category get a list of the posts associated with that category. Not much really, but useful in some circumstances.

WordPress Logo

Wordpress 3.0 Released!

18th June 2010 - 2 minutes read time

It's been a while in the making but yesterday saw the release of the latest major version of Wordpress. I had a feeling it would be pretty soon as there as the final release candidate (RC3) was released last week. You can the Wordpress 3.0 download page below:

Download Wordpress 3.0

PHP Logo

PHP Paragraph Regular Expression

9th June 2010 - 2 minutes read time

I quite often find the need to extract a section of text from the beginning of a blog post or similar to be used as the excerpt. I normally use a function that will count the number of whole words available and return the string containing those words.

A good alternative to this, although only applicable if the original post is in HTML, is to use a regular expression to extract the contents. The following code will take a string and extract just the first paragraph of text.

PHP Logo

Find A Month From A Given Integer With PHP

7th June 2010 - 1 minute read time

If you need to know the month from a given integer (from 1 to 12) then you can use the following snippet. This will return the string "Feb".

date("M", mktime(0, 0, 0, 2));

This can be encapsulated into a function call that will take a number between 1 and 12 and return the corresponding string for that month. This function includes some simple error checking to make sure that the number is valid before trying to work out the date.

PHP Logo

Palindromes In PHP

1st June 2010 - 3 minutes read time

Richard Wiseman is a psychologist, magician, and author who runs a little blog over at http://richardwiseman.wordpress.com/. His blog talks about all sorts of things, but every Friday he posts a little puzzle that you can have a go at solving.

The last puzzle posted talked about palindromic numbers and speed, here is the puzzle in full.

The other day I went for a bike ride. My favourite route has signs every meter saying how far you have travelled. I came across the sign saying '15951 meters' and thought 'Oh, that's interesting, it is a number palindrome because it reads the same from left to right as right to left'. Then I rode on. Two hours later I came across the next palindromic number sign. How fast was I going?