A Colophon for Drupal

I wanted to put together a colophon for my Drupal site that would show the current installation details—pulling the information from the live site rather than relying on me to remember to update it after each change. With one module, three views, and a tiny bit of PHP and JavaScript, it’s now working.

Module needed: Views System (and any dependencies not yet installed).

Put the code snippets below in blocks, make the views described below as blocks also, then mix together on a page. Voilà!

Code to obtain Drupal version:

<?php print VERSION; ?>

Code to obtain paragraph font:

<p id="fontnameforcolophon">not determined</p>
<script type="text/JavaScript">
(function() {
   var elem1 = document.getElementById("fontnameforcolophon");
   var style = window.getComputedStyle(elem1, null);
   elem1.firstChild.nodeValue = style.fontFamily;

View to display themes in use:

fields: System: Display name, System: Base theme (Base theme)
filter criteria: System: Type (=Theme), System: Status (Enabled)

View to display core modules:

fields: System: Display name, System: Project
filter criteria: System: Status (Enabled), System: Drupal core (Yes), System: Type (=Module)

View to display additional modules:

fields: System: Display name, System: Project
filter criteria: System: Status (Enabled), System: Drupal core (No), System: Type (=Module)


Bash script for updating Drupal Core

Updating Drupal core always makes me a bit nervous, as it involves ripping out the old version and inserting a new. Not having access to Drush, I decided to make a shell script that would automate the steps, eliminating the usual risk of human error. The following is the script. It’s heavily commented, so I’ll keep extra remarks to a minimum.

The script takes one argument, the full URL of the new Drupal version (e. g., http://ftp. Drupal.org/files/projects/Drupal-7.19.tar.gz). Line 20 in the script is the only one that needs editing to match your installation.

Be sure to read the warnings in the first few lines. You need to put your site into maintenance mode prior to running the script, run update.php after, then test and take out of maintenance mode. Also, remember to back up your site!

  1. #!/bin/bash
  3. # Before updating Drupal, BACK UP YOUR SITE. http://Drupal.org/node/129202 explains how. Also, set site into maintenance mode.
  4. # After running script, run update.php, then take out of maintenance mode (if everything is working OK).
  7. # Check for proper number of command line args.
  9. E_BADARGS=65
  10. if [ $# -ne $EXPECTED_ARGS ]
  11. then
  12.         echo “Usage: `basename $0` {arg}”
  13.         exit $E_BADARGS
  14. fi
  16. #for the following steps, stop immediately if something doesn't work
  17. set -e
  19. #this is a cd to your Drupal site's root directory, change as needed
  20. cd ~
  22. #get the update
  23. wget $1
  25. #remove path from the wget argument to get name of file
  26. NEW_VERSION=${1##*/}
  27. tar -zxvf $NEW_VERSION
  29. #remove .tar.gz from NEW_VERSION to get untarred directory name
  32. #run through the rest even if there are errors
  33. set +e
  35. #just to be sure, check to see if we can see a file in the untarred directory—otherwise, don't delete the old site!
  36. #if we can see the file, then delete old files (as used in Drupal 7), copy new distribution into site, compare old htaccess and robots to new, remove temporary files
  37. if [ -f $USE_DIRECTORY/index.php” ]
  38. then
  39.         rm -f robots. txt.old htaccess.old
  40.         cp robots.txt robots. txt.old
  41.         cp .htaccess htaccess.old
  42.         rm -R -f includes misc modules profiles scripts themes
  43.         rm -f .gitignore .htaccess authorize.php CHANGELOG.txt COPYRIGHT.txt cron.php index.php INSTALL.txt install.php INSTALL.mysql.txt INSTALL.pgsql.txt INSTALL.sqlite.txt LICENSE.txt MAINTAINERS.txt README.txt robots.txt update.php UPGRADE.txt web.config xmlrpc.php
  44.         cp -R $USE_DIRECTORY/ .
  45.         diff .htaccess htaccess.old
  46.         diff robots.txt robots. txt.old
  47.         rm -R $USE_DIRECTORY
  48.         rm $NEW_VERSION
  49.         rm INSTALL*txt install.php
  50. else
  51.         echo $USE_DIRECTORY not found”
  52. fi


One-Line Script to Refresh a Web Site Cache by Spidering all Sitemap Entries

Well, the title says it all. I wanted to refresh my web site’s page cache, as some pages are very slow loading otherwise. The site can (with the Drupal Boost module) serve pages without having to reconstruct them if they are in the cache.

After some digging around and consolidating information from a number of sources, I came up with the following that reads the xml sitemap for the site then checks each page without downloading it. Remember to replace www. example.com/sitemap.xml with the correct URL for your sitemap.

/usr/bin/wget -q http://www.example.com/sitemap.xml -O - | /usr/bin/awk -F'</?loc>' 'NF>1{print $2}' | /usr/bin/wget --spider -q -i -

Note that, while the above may be broken into several lines on your browser, it should be a single line for the shell command line unless you use line continuation characters.

I added it to my crontab to run immediately after the Drupal cron job in crontab by adding it on the same line as the Drupal cron job, with a semicolon (;) in between the cron job and the spider commands.


Some basic Drupal 7 modules

I have just started working with Drupal 7. It is a great content management system but its modularity (and anarchic module development ) means that you have to browse through the many modules to find the ones suited for constructing your site. Here are a few that probably every site could use. Some of these modules are less than intuitive to install (e. g., CKEditor, Superfish), so read the installation instructions carefully.

One other change that will fix a bizarre spacing problem with the HTML editor: disable the convert line breaks into HTML setting (or move that filter up to first in order) in the HTML text formats. Else it will go crazy after some other processing, such as External Links, and add line breaks in the oddest locations.

Mandatory for a well-behaved site

  • CKEditor: to enable a decent page editor.
  • CKEditor Link: so you can link safely to internal pages, even if you later change the URLs.
  • CKEditor SWF: to improve CKEditor's woeful SWF plugin.
  • Advanced Help: to enable the help pages of some modules.
  • Backup and Migrate: to back up your site.
  • Global Redirect: to improve URL structure and function.
  • Mollom: smart spam filter.
  • Pathauto: to improve URL structure and function. Requires the Token module.
  • Search 404: to provide a useful page not found page.
  • Security Review: to check for site vulnerabilities.
  • Site map: to give users a site map.
  • Redirect: to intelligently guide people to moved pages (and eliminate redirects that are unused).

Very useful, probably needed for most sites

  • Chaos tools: needed for many of the other modules.
  • External Links: allows you to control the behavior of external links (e. g., display an external link symbol, open up new page, display disclaimer, etc.)
  • jQuery Update: to get a more recent version of jQuery than the one provided with Drupal.
  • Panels: flexible content management.
  • Views: flexible content management.

Nice to have for specific tasks

  • Superfish for dropdown menus (Drupal has single-level menus only!). Note that the style should be set to none if you want to use your theme's styling (which you almost always want to do). Requires the Libraries module.
  • Quicktabs for tabs on pages. See Little Book Club for an example of its use.


Subscribe to Drupal