Services

  • Drupal CMS Developer
  • Website speed optimisation
  • Drupal 6 to Drupal 8 migrations

Welcome

Welcome, I am a Web Developer based in Madrid, Spain originally from the UK. I studied Computer Science & eBusiness at Loughborough University. I specialise in Content Management System websites

Will's Scripts & Functions

Below are some of the snippets of code that I have found useful over the years. Most of them are available and better documented on php.net or respective API sites but I have collected together some of the more common ones that I use or took a long time to find.

 

 

Use the filter form below to filter the scripts and snippets by category...

Drupal 6 pay2publish / Pay per Node

I needed a pay per node solution for Drupal, I was very surprised at the distinct lack of modules for this in Drupal! I have started to port the uc_nodetype module for ubercart but have hit some issues. If anyone is interested in helping me with this, then please let me know.

It mostly works quite smoothly, the only problem I have is trying to display the node edit form on the cart checkout page, it either breaks the page or doesn't show any field elements. It should be such an easy thing but I can't figure it out.

Drupal 6 pay2publish / Pay per Node

I needed a pay per node solution for Drupal, I was very surprised at the distinct lack of modules for this in Drupal! I have started to port the uc_nodetype module for ubercart but have hit some issues. If anyone is interested in helping me with this, then please let me know.

It mostly works quite smoothly, the only problem I have is trying to display the node edit form on the cart checkout page, it either breaks the page or doesn't show any field elements. It should be such an easy thing but I can't figure it out.

Varnish + CDN - if file doesn't exist fetch from another domain

If you are working with complicated sites with CDNs, especially with imagecache whereby because Drupal says to replace the domain with a CDN domain, the URL called is not Drupal and so never generates the image, then heres the solution. I use varnish as well so am able to say "if the image returns a 404 error, try fetching it from original Drupal domain"

  if (req.url ~ "\.(png|gif|jpg|swf|css|js)$" && req.http.host ~ "^mycdn\.domain\.com" && beresp.status == 404 ) {
      set req.http.Host = "mydrupal.domain.com";
      return(restart);
  }

Varnish multiple domains but images shared

Ever had a Drupal multisite where the images are all stored in the same folder and shared for all sites? Ever installed varnish and noticed how much RAM gets used by photos? Well I did, and realised that I had 5 copies of every image, one for every domain. Easy thing to fix this:

  if (req.http.host !~ "^maindomain\.com" && req.url ~ "my/images/folder") {
    set req.http.host = "maindomain.com";
  }

Can't set custom log format for Varnishncsa with systemd

In the old days before systemd we updated /etc/default/varnishncsa enabling it and setting a custom format should we so choose. Now its a little more complicated. As this file says:

# Note: If systemd is installed, this file is obsolete and ignored.  You will
# need to copy /lib/systemd/system/varnishncsa.service to /etc/systemd/system/
# and edit that file.

Drupal 6 override theme for a page in a module

This is actually quite simple. Lets say you want to override the admin theme only when creating a new node of type TYPEX

Drupal - completely render another node including hooks

If you need to completely load another node in a module which includes the content element of the node object then use the following code...

<?php
$node
= node_load($nid);
$node->build_mode = 'full node';
$node = node_build_content($node);
drupal_render($node->content);
content_alter($node);
?>

Just replace $nid with your node id that you want to render and your $node is ready to go.

Pasat 4b Payment Method (uc_pasat4b) setup instructions

I was receiving errors from the bank system after having installed the uc_pasat4b module - http://www.ubercart.org/project/uc_pasat4b. After having used the sermepa system for every other website I have built, I was totally confused as to why it wasn't working and why the module wasn't sending all the data that I thought it should be.

Remove "not verified" from comments

Just insert the following code into your template.php in your theme...

<?php
function phptemplate_username($object) {

if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}

if (user_access('access user profiles')) {
$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
}
else {
$output = check_plain($name);

Place a link to a view page next to the node edit link

I was trying place a link to a views page in the tabs that appear on nodes, I wanted it to appear link "Node Edit MyNewLink". The way to do this is to set the page URL "node/%/MyNewView", and create a normal "menu tab". The link will automatically appear, just make sure you replace "MyNewView" in your view path to something relevant.