PHP Utility Functions: get_value_or_default

Some handy functions I use to grab values from arrays and objects (especially $_REQUEST and friends), without having to constantly run isset or !empty checks everywhere (to avoid undefined index notices). You can specify a default value if the index doesn’t exist in the array or object. Also lets you sanitize the value(s) using a callback before returning them.

Note: No amount of helper functions will protect you from Bad Things. Always validate/sanitize untrusted data.

$var ) ? $object->$var : $default;
	elseif( is_array( $object ) )
		$value = ! empty( $object[$var] ) ? $object[$var] : $default;
		$value = $default;

	if( is_callable( $sanitize_callback ) ) {
		if( is_array( $value ) )
			$value = array_map( $sanitize_callback, $value );
			$value = call_user_func( $sanitize_callback, $value );

	return $value;

function get_request_var( $var, $default = '', $sanitize_callback = '' ) {
	return get_value_or_default( $var, $_REQUEST, $default, $sanitize_callback );
function get_get_var( $var, $default = '', $sanitize_callback = '' ) {
	return get_value_or_default( $var, $_GET, $default, $sanitize_callback );
function get_post_var( $var, $default = '', $sanitize_callback = '' ) {
	return get_value_or_default( $var, $_POST, $default, $sanitize_callback );

PHP Magic: Building a static countdown clock using PHP and GD

Update (2010-04-20): These Gleeks are crazy. Since being released, the clock has been viewed over 200,000 times. Insane.

If you like Glee, you’ll like this. If you like image processing using PHP, you’ll like this even more.

Using PHP and the GD image library*, it’s pretty easy to create a static, image-based countdown clock, which is useful for situations where javascript cannot be used (think A new image is automatically generated server-side for every minute (assuming a request is made for the clock for that minute), and all images are cached to avoid killing the server processor. Check it out in action on Gleeks United or after the jump.

Don’t have code yet, but I’ll post it when I get a chance.

Continue reading

Mockingbird: wireframing made awesome

Wireframing is awesome!

Using Mockingbird, a recently launched Cappuccino-based wireframing tool, I was able to whip up some quick UI concepts I’ve been thinking of for the next iteration of Edit Flow. Though obviously not as fast as a hand-drawn sketch, it’s far more convenient when you’re working with other people since you don’t have to get cameras and/or scanners involved.

Mockingbird has a fairly intuitive interface, and most functionality you’d expect from a wireframing/diagramming tool. Best part: no Flash! Check out the result below. It’ll be updated as I make changes to the diagram.

Continue reading

WordPress Plugin: Plugin Notes

This is the outcome of a couple of hours of Friday night coding after an open call by Chris Coyier over at Digging into WordPress. Here’s what Chris asked for:

Ever look through your list of plugins and forget just exactly what one of them does? I know they have descriptions next to them, but that doesn’t always speak to exactly what you are using it for and why. This plugin would just put a text field in each plugin field you could type some notes in there, theoretically to keep information about why and how you are using this plugin.

And since I was bored (and thought this was a pretty useful idea), I delivered. Plugin Notes is exactly what it sounds like.

Once you install and activate, the plugin adds a link “Add plugin note” that lets you add in a little note next to each plugin. It’s totally ajaxified and full of cool goodness. (Unfortunately, I was a bad programmer and didn’t make plugin gracefully degrade when javascript is turned off. Sorry, folks. Maybe next time.)

Plugin Notes: adding a note is easier than milking a cow.

Plugin Notes: adding a note is easier than milking a cow.

When a note is added, it shows up inside a little blue box and includes the name of the user that added the note as well as the date and time when the note was added. You also get handy dandy options to “Edit” or “Delete” notes.

WordPress plugin: Plugin Notes - blue boxes make things look pretty.

WordPress plugin: Plugin Notes - blue boxes make things look pretty.

Each plugin can only have one note. I can imagine there would be cases where multiple notes may come in handy, but those would be rare so I’m passing on that functionality.

The plugin is pretty simplistic, and unlikely to see any future feature additions (unless someone really, really wants one). I’ll keep a watch for compatibility with future versions of WordPress though, so rest easy.

Excited, enough? Grab Plugin Notes (from the WordPress Plugin Directory) or download it from within WordPress.

Note: you’ll need PHP5 and a javascript-enabled browser for the plugin to work.

Digital Design Project:

My independent digital design project (DAC 400) completed as part of my Digital Arts Communication specialization explored the push by magazines into the online and technology spaces. The goal of the project was to explore viable technologies to use as a platform for developing an online presence for The Boar, an arts and literary magazine produced by and for the students in the Faculty of Arts at the University of Waterloo. I explored the traditional online website format but looked further by designing a prototype of an up-and-coming Flash-based technology known as the “digital edition.” This “new technology” is being adopted industry-wide like wildfire (see Issuu, Scribd, Zinio, etc.). It takes a traditional PDF and converts it into an interactive magazine-like object on a webpage that can be used and manipulated much like a physical magazine. My prototype (although not entirely functional) took a step further and explored the possibilities of creating greater ties between a magazine’s website and their digital edition via a synchronization of comments, bookmarking, and other social networking type tools.

As supplementary materials, I have attached 3 documents that I completed as part of my project:

  • Technology Research: exploration of various technologies in use by the magazine industry and what movements the trends were indicating.
  • Strategy, Scope & Structure: Documentation outlining requirements for the online presence and drill down into specifics, as well as a high-level architectural diagram.
  • Final Analysis: Analysis of the end result of my project, including rationale for technical and design choices as well as possible enhancements for the future.

Also included is a somewhat-working version of the digital edition prototype.

The website in its current state, which has deviated slightly from the original design, can be found here:

Web App prototype: eCard Builder

KiwiShake was a prototype Facebook application. The idea was to provide users with the ability to create eCards that could be customized with photos, videos, etc. It’s not even close to completion and it pretty terrible overall, but there’s a lot of potential.

I programmed the interface of the application, which involved lots of JavaScript and some AJAX work.

See a somewhat functioning prototype here:

Tools used: JavaScript, Aptana IDE, YouTube API, various JavaScript libraries

Development: Imprint Online – Web Publishing System

Imprint Publishing

What do you get when you marry the Adobe Scripting Engine with the magic of XML Parsing? Well, one thing you can come out with is a web publishing system that automates the process of publishing the online version of a weekly newspaper.

This is exactly what I did for Imprint. Online publishing for Imprint was always seen as a chore and took forever to do. I searched for a solution, but could not find anything substantial. So it was time to hack something together.

Using the powerful Adobe Scripting Engine and some cleverly crafted JavaScript, I was able to turn an (almost) semantically dead laid out newspaper page (in Adobe InDesign) into a meaningful XML file. (I have to note that some user input was involved; the Web Editor had to appropriately label related Text Boxes within InDesign to associate story elements together). This XML file could then be pumped into a custom administration component for the Mambo CMS, that would parse through the XML and create the appropriate database entries and automagically publish the newspaper online (I should also note here, that some user input was involved; Users were walked through the list of articles extracted from the XML file and had to indicate the Section and Category each belonged to). Goodbye copy-pasting!

Clever, no?

Tools used: JavaScript, Adobe Scripting Engine, Adobe InDesign, XML, PHP, MySQL, DOMIT XML Parser, Mambo, and hours of rigorous testing


Development: Imprint Archives

Imprint Archiving

In conjunction with the 50 years of campus journalism celebration at the University of Waterloo, Imprint took made a push to make available online, all 50 years worth of its archives. I took the lead on this as I managing the Imprint website at the time.

We received scanned copies of all the archives in PDF format. To incorporate the archives into our existing system, and to make them easy to browse through, we needed certain pieces of information, such as the volume, issue number, etc. The files were all named with a certain convention and contained all the required pieces except for a key component: the date. Getting the date would be hard; there was no easy solution other than simply opening each PDF file and recording the date manually. The downside to this was that 50 years worth of archives meant that a lot of PDF files needed to be sifted through.

Given the access to a healthy and willing volunteer base, I decided to use “community” power to streamline the process. I set up a quick PHP script that extracted volume and issue information from the file name, and on top of that, threw a quick streamlined interface that asked the user to enter the date information for the PDF file presented. With volunteers working at the task in their spare time, we managed to codify 50 years worth of archives (1,000+ issues in less than a week), whereas, my going at it alone would have taken easily over a month.

Take a walk down history lane here: Imprint Archives

Update (2008-06-04): I recently upgraded the archives to make use of the Scribd API to generate on-the-fly “iPaper” versions of PDFs in the archives. The main benefits of this are savings in bandwidth usage (since some of the PDFs are ~100MB) and a faster, enriched user experience.

Tools used: Healthy and willing volunteers, PHP, MySQL, Regular Expressions

Development: Imprint Online

Imprint Online Imprint Online Administration
After several years in the online game, Imprint, the University of Waterloo’s official student newspaper, decided that it needed a fresh new website to adapt to the changing trends in the Internet news industry.

I modified the core code of the Mambo content management system to meet the unique needs of a newspaper’s online counterpart, such as having an issue-based publishing system, among others. This involved modifications to both front- and back-end code+interfaces. Beyond this, I investigated add-ons provide additional functionality such as a commenting system and integrated those into the website. If add-ons were not readily available or were not up-to-standard in terms of quality, I wrote them from scratch. A great example is the PDF Archive.

Tools used: Mambo CMS, lots and lots of coffee (for all the late nights spent analyzing and writing code)