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 […]
Category: Web Development
Using jQuery UI with Drupal 7
Like jQuery, the jQuery UI user interface library (version 1.8.7) is already included and registered by the system module of Drupal 7. All you need to do is enable it. You can include jQuery UI in the PHP editor of a single node or module: If you add an individual effect, Drupal will add the […]
Ubuntu 16.04 Web Server with Apache, PHP, and MySQL
Ubuntu 16.04 LTS has been out for a little while now, and its standard repos offer some nice enhancements over Ubuntu 14: Apache 2.4.18, PHP 7, and MySQL 5.7.12 The process for creating a basic LAMP web server is also streamlined, as a couple of bugs that plagued Ubuntu 14.04 are now eliminated. To create […]
Ubuntu 16.04 Web Server with Nginx, MariaDB, Redis, and Drupal 7
The Drupal 8 version of this article can be found here. As of today, April 21, 2016, Canonical has released Ubuntu 16.04 Server, supported until 2021. Ubuntu 16.04 has some nice enhancements, and some changes that will affect sysadmins and developers: it ships with Python 3 as the default Python, plus PHP 7, MySQL 5.7, […]
Drupal 7 Search Engine Optimization (SEO)
So I recently migrated my web site to Drupal after running it in WordPress for several years. Not surprisingly for a redesign where all the URLs changed and much content was added, my traffic numbers cratered, but after some tinkering they’ve gone back up again. After this little experiment with SEO, here are some things […]
jQuery: Summarize Table Entries
Simple jQuery script for summarizing the results of my Amazon book listing. Since jQuery is already included in Drupal, I figured I’d use it to summarize the ratings and values. Note that in Drupal (and WordPress), jQuery defaults to noconflict mode so the “$” shortcut isn’t available. You can override this by setting jQuery.noConflict(false) or […]
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; […]
Python: Webscraping With BeautifulSoup
Some experiments in website scraping using Python 2.7 with BeautifulSoup 3.2. The first function here shows various manipulations of an HTML page, including saving a scrubbed file to disk. The second function shows a simple crawler that attempts to traverse a domain and build a sitemap from hyperlinks encountered in the pages. Includes some commentary […]
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 […]
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 . […]