Drupal 7: Display Page Elements Conditionally

In Drupal you often need to show page elements conditionally, usually based on variables like the URL or user identity. Fortunately, the Drupal API offers several functions that can help: hook_html_head_alter() template_preprocess_page() template_preprocess_html() drupal_match_path() drupal_get_http_header() user_is_logged_in() or user_is_anonymous() Modify the Page Header To add a tag to the header on every page, use hook_html_head_alter() in […]

Loading

Read More

Bash: WordPress Installer

A basic WordPress installer in Bash. Assumes Ubuntu 14.04 LTS, so adjust as necessary. The end-of-line backslashes here are added for ease of display, so remove them before running this. #!/bin/bash # Set sitename and directory for WordPress WPDIR=/var/www/wordpress; SITENAME=mydomain.com; EMAIL=myemail@somewhere.com; # Download latest WordPress and untar it wget https://wordpress.org/latest.zip; unzip latest.zip; mv wordpress/* $WPDIR; […]

Loading

Read More

VB.NET: Basic JSON and LINQ

A simple console application that downloads and processes JSON data using .NET 4.0 with the Newtonsoft Json.NET library. The sample data is a list of kings and queens of England and the UK from http://mysafeinfo.com/api/data?list=englishmonarchs&format=json. This uses simple LINQ but the Newstonsoft LINQ to JSON API will be more efficient in many cases. Mysafeinfo.com returns […]

Loading

Read More

PHP: List Last Updated Files

An old PHP script to list the most recently updated files within a web site using their ‘last modified’ time stamps. <?php $rootdir = $_SERVER[’DOCUMENT_ROOT’]; if ($dir = opendir($rootdir . ‘/my/web/site’)) { $filearray = array(); $i = 0; $exclusions = array(‘.’, ‘..’, ‘inc’, ‘css’, ‘images’); while (false !== $file = readdir($dir)) { if (is_dir($rootdir . […]

Loading

Read More