Drupal is a Content Management System (CMS) which is used by many popular websites such as The Onion, MTV UK, Spread Firefox and your very favourite blog, Thingy Ma Jig.
It's favoured for its strong development potential.
Following Kevin Hankens post on why you shouldn't ignore Drupal 404 errors, I decided to go through yesterdays error_log on our live apache server (the one which hosts www.pponline.co.uk, www.sportbusiness.com and www.mychild.co.uk alongside around 40 other dupral sites).
Today I needed to quickly find out a list of node's which did not contain a certain token (one we use on PPOnline to insert adverts into articles). There were meant to be 2 of these tokens per article but we had noticed some only had one. Some didn't have any at all!
Now, this might already exist as a neat function somewhere, but I couldn't find it. So I wrote this little query to find the number of occurrences of a substring in a larger block of text.
I did look into using the SUBSTRING() and SUBSTRING_INDEX() commands, however I couldn't see a way of efficiently using them to find any number of occurrences. So I settled on the following…
A while ago we started having issues running a website. Bandwidth. Upon investigation, we saw that the majority of bandwidth was being use by image files and of those, lot was from the ImageCache folder. It was also causing a lot of excess server load by consuming Apache processes. Something needed to be done.
I recently stumbled across a handy tutorial on configuring a Drupal dictionary in Vim for autocomplete. I also remembered helping a friend out with a similar problem, Drupal syntax highlighting for Nano. I then combined the two and have a simple to follow tutorial for generating your own drupal 6 dictionary for vim autocomplete!
I just updated this server to PHP 5.3. As all my sites are Drupal 6 it seems I have a few issues ahead which mean I need to patch Drupal to stop PHP complaining about deprecated stuff…
So I headed over to the post on drupal.org which is discussing 5.3 compatibility in Drupal 6 (which I personally think SHOULD go in) to grab a patch. I applied the patch with no problems. I refreshed a page and got a white screen so I checked the logs only to see…
I like little wins. I was just looking through the CSS file for this site and noticed that - for some reason - I'd used 0px instead of a LOT of times. Most values need numbers (10em, 10px, 10% and 10pt are all very difference sizes) however 0 is one of the few valeus which is the same in all cases (0px, 0pt, 0% and 0 are all zero!). This adds up to wasted data and bandwidth; admitedly not a lot, but still Every Little Helps!
So I fired up Vim. Initially, I just did:
I just hit an interesting issue while trying to upgrade a Drupal 5.18 site to Drupal 6.12. I went to the update.php page and noticed an error at the top implying the url_alias table was having issues due to Drupal 6 expecting a language column which wasn't present in Drupal 5. "No problem" I thought, "That'll get fixed during the update!". This was the beginning of a long learning curve through the new <a href="http://api.drupal.org/api/group/batch/6">Batch API</a> system!
Back in November last year, I wrote a script which handled backing up a drupal database. There were quite a few comments and I've taken some on board and developed the script on a little further to be more "generic".
One of the main complaints/suggestions about my previous snippet was the hard coded nature of it. The follow script offers far more configuration through the command line itself.
This morning I updated a site to the latest release of Drupal 5.16. Nothing special there at all. I've done that many times as has (hopefully) mabye other drupal devs… However, I'm a bit of a newbie when it comes to SVN. Didn't I mention this drupal site was in an SVN repository? ;-)
So, I've svn copy'd the trunk to an "update_to_5.16" branch, checked out this branch and done a cvs up -dP -r DRUPAL-5-16. Everything is going according to plan so far. Next I run svn status to get a list of files which I need to mark as added or deleted (or to list anything else which has gone wrong). What happens next is I get a list of hundreds of CVS Template files which have been added to the CVS folders. For example…
The first test is a valid email address test. The second test is if an account exists for that email address. The third is if the username, generated by the "user" part of the email address, exists. If there are any issues, the "error" is logged into and array and printed at the end.
As the function goes along, a user is saves with the user part of the email address as their name, a random 6 character password and the email address as the contact address. In this example, it also give the user role number 3, which was our "subscriber" role.
I am a bit of a "neat geek" when it comes to coding. Things should be indented neatly and should have well laid out comments! Why? Well… It's easy to do and in 6 months time when you look at your code you will appreciate it! It will also me even more appreciated by another developer in less than 6 months time ;-)
As many readers might know, I use Lighttpd a lot. I really like it for many reasons. Its fast, free, easy to configure, very light-weight (handy if you're running a cheap VPS or a low end server)… This is very apt for me because almost EVERY website I make now is a Drupal site (why would you use anything else?!).
Drupal is, inherently, a rather large web app - mainly because of its ability to do nigh-on anything. This means one needs to be a little careful about what you do with your resources. From my experience, Apache (which is bloody brilliant) can tend to get a little "bloated". I know there are ways of slimming it down and improving it, but I also like playing with new toys too! This is when I moved over to Lighttpd…
I was just dumping a database using mysqldump and I noticed that tables such as cache (and its cousins cache_page, cache_menu, etc), sessions and watchdog can be pretty big and are also not often essential for backing up. I mean, when you restore your web site do you really care about restoring people's logged in sessions from when the backup took place? I can understand maybe keeping watchdog; but then again should you lose your site you would probably lose it several hours after the backup so would miss out on any relevant watchdog notices.
Anywho… I did a mysqdump for a large database for a website I maintain and the dump came out at 400Mb. I then spent a few minutes cobling together a small script which would do a mysqldump but had some pre-programmed Regular Expressions to match specific groups of tables which it would only dump the structure for (ie, no data). After running this script, the SQL dump was only 220Mb. Much better! It also runs considerable quicker too and will cause less table locking.
So - the script?
I while ago (almost a year!) I released a module called Relevant Content to the community. This module executes a relatively lightweight SQL query which pulls up other nodes and sorts them by how many terms they have in common with the current node you're looking at. This provides a rudimentary method of suggesting other content to visitors to the page. It also provides a way of teaching search engines about other potentially relevant content.
My first theme, Abessive, gets a new release today for Drupal 6. Turns out to be a pretty easy upgrade!
In case nobody caught onto what Abessive was the first time; it is an (almost) image free theme with flexible 1, 2 or 3 column layout (depending on where/if you place any blocks). Each block/section has rounded corners and slight top & bottom gradient which is achieved using only CSS techniques involving margins, padding and background colours. This makes the theme very lightweight and elegant at the same time.

I just finished upgrading a server to Ubuntu 8.04 which came with Vim 7.1 rather than 6.3 on the older server. It seems 7.1 does things slightly differently to 6.3.
In 6.3 I could create ~/.vim/filetype.vim and in there define a line as follows:
au BufRead,BufNewFile *.module,*.install,*.theme setf php
However in 7.1, it looks like a line similar to this has to go into ~/.vimrc instead…
After recently reading about how great VIM is for the three hundredth and fifty second time (I kept count), I decided to take a look.
It really is quite cool! I've also decided to try to log any cool tips I learn about it. Here is the first which I found after running the coder module on one of my modules (Page Title 2) and it threw hundreds of errors about too many trailing spaces on empty lines.
One of my most popular Drupal modules - Global Redirect - has just had an update from 1.2 to 1.3. This update includes several fixes for the following:
I have just finished commiting my very first theme to the drupal community! I'm not a designer by nature - I prefer to be deep in the code. Thats why I commited this theme - it contains very little design (in terms of Photoshop work). This design is, pretty much, image free! On top of that - its SEO friendly too!

I say 'Pretty much' because it is still using 3 core image files for the bullet points. But what I'm pleased about is the curved CSS-only corners with a slight gradient on them AND the fact that if you remove content from a column, the content fills out over it automatically.
I've just released Page Title 2 for Drupal 6. Page Title 2 is still marked as Alpha (as a project) however its in use on a number of my sites and appears to work.
I'd appeciate people's feedback regarding this module. Its a GREAT way to improve your websites SEO!