Drupal 7 port.

Credit goes to Ryan Dial for doing about half of the work.