background top

Take a look at Noah's bio.

DemoCampGuelph

DemoCampGuelphOn Wednesday, Gavin and I had the pleasure of attending DemoCampGuelph at The eBar in downtown Guelph. This was the first time either of us had been to this type of event, which was of the BarCamp variety. A BarCamp is an informal gathering in a public space, usually a bar, where demos, discussion and general socializing take place.

The event in Guelph is organized primarily by Brydon Gilliss (twitter: @Brydon). There were a limited number of presenters and we were among the privileged few who were chosen to show off what we’ve been working on. There was a variety in the types of projects: some, like ours, were pure software and others combined software and hardware.

Tara Hunt (twitter: @missrogue)
First up was the special guest speaker, Tara Hunt. Tara is the author of The Whuffie Factor, and had many interesting things to say about social media as it applies to individuals and companies. Regarding individuals branding themselves, she said “Who needs a personal brand? Get a personality!” To business, the comment was simpler but along the same line “Stop being robots”. Basically what she was saying to everyone is to be authentic. Whether we work for a small company, large corporation or are self-employed, we are still human beings with our own interests, passions and even flaws. She used the example of karaoke and how it allows people to relate to her better. Social media does more than just connect people, it embraces the human factor in everything we do.

Tiny Hippos (twitter: @tinyHippos)
This group built a browser plugin for mobile website and widget developers to aid in the laborious process of testing with multiple devices. This saves the time and effort of running multiple emulators. This project was still in its early stages and we were among some of the first to see it in action.

BerryBlab (twitter: @berryblab)
BerryBlab is a clean easy-to-use BlackBerry application to read vBulletin forums. This program has a clear purpose and achieves it well.

Compost (twitter: @compostr)
This was our presentation of our new opensource web design feedback tool. The hardest part was demoing in under 15 minutes, including setup and questions. After taking a quick tour through the demo website, we fielded several questions from the audience.
My two favourite questions were (paraphrasing a bit):
Q: What distinguishes Compost from similar software, such as ConceptShare or others?
A: Ours is free.
Q: How do you plan to make money off this product?
A: We don’t. The time savings of using the program translate to money indirectly, but the code itself is opensource under GPL3 and free for anyone to use.

JaxCore (twitter: @jaxcore)
JaxCore is looking to change the way web development is done by introducing a new language. The biggest challenge we can see is getting programmers to let go of their favourite programming languages.

SnapSort (twitter: @snapsort)
This is a camera comparison website with a bit different spin than many others. The application looks at the specs and compares them weighted by what’s actually important to consumers. If you’ve ever tried to compare cameras online, you’ve experienced the frustration of trying to figure out what any of the stats actually mean. This site might help me in finally deciding which digital SLR to buy.

Little Robots (twitter: @tonious)
This was a very interesting demo, though very hard to see in the packed room. He addressed the basic issue of subtle communication between individuals. The developer built two little robots, one for his fiancĂ© and another for himself. By pushing the belly-button on his robot, his fiancĂ©’s robot waves at her, and vice-versa. Very cool. But since I know little about hardware, I’ll stick with text messaging my girlfriend for now.

All around, it was a great event and I would love to see a DemoCampLondon. We have a number of specialized user groups: one for Drupal, another for .NET, and of course many great networking groups such as the GeekDinner, but nothing quite along these lines. Seeing a variety of cool products in development in a casual grassroots manner was a different experience and one I look forward to next time.

photo by MonsterFarm

Drupal CCK Select Values to an Array

I really enjoy using CCK to define custom content types and it is usually does the trick all on its own. However, sometimes I need to get the field data out in some other way. This example retrieves CCK select options and returns them as an associative array, which can then be used in a custom form or elsewhere.

function _module_events_types_array() {
	$query = "SELECT global_settings
		FROM {content_node_field} AS cnt
		WHERE cnt.field_name = 'field_meeting_type'";

	$queryResult = db_query($query);

	while ($meeting_types = db_fetch_object($queryResult)) {
		$meetings = unserialize($meeting_types->global_settings);
	}
	$meeting_list = explode("\n", $meetings['allowed_values']);
	$meeting_array = array("" => "All Meeting Types");
	foreach($meeting_list as $meeting_type)
	{
		$meeting = explode("|", $meeting_type);
		$meeting_array = array_merge($meeting_array,
			array($meeting[0]=>$meeting[1]));
	}

	return $meeting_array;
}


Disabling WYSIWYG on comment field in Drupal 6

Integration of wysiwyg editors into Drupal continues to evolve and we can expect to see even more improvements in Drupal 7. In Drupal 6, the TinyMCE module was discontinued and the WYSIWYG module has taken its place. The WYSIWYG module works as an api for integrating editors such as TinyMCE, FCKeditor, markItUp, NicEdit and Whizzywig.

One important feature that WYSIWYG lacks is the ability to exclude certain form fields. We ran into this issue when we wanted to disable wysiwyg formatting on the comments field. There had been suggestions here and here on the drupal forums about setting a #wysiwyg attribute; this we tried with no success. Another suggestion was to use the Better Formats module, but the thought of adding yet another module for something so simple wasn’t very appealing.

In the end, we ended up writing a small amount of code to achieve this. We added the following function to our custom module. What we’re doing here is removing the ‘format’ entirely from the comments field. If you needed to alter a different form, replace comment-form with the id of your form and comment_filter with your field. You may need to try a print_r($form_id) to find out the id of your form item.

function my_module_form_alter($form_id, &$form) {
  if ($form_id['#id'] == 'comment-form') {
    $form_id['comment_filter']['format'] = array();
  }
}

Drupal – Import data into nodes and content types

Importing data into Drupal can be a bit complicated because of node revisions. The trick is that the data needs to be inserted into the node and the node revisions tables, and the two need to reference each other. This becomes even more complicated when using custom content types which also need to reference these nodes.

The function insert_node() takes the node title, body, content type (such as ‘page’ or ‘event’), and optionally the date (as a unix timestamp). It uses two global variables for the ids so that you can reference the ‘nid’ and ‘vid’ values for the inserted rows in other functions, as illustrated in the example insert_special_node().

function insert_node($title, $type, $body, $date = '')
{
	global $insert_id, $insert_revision_id; //nid and vid

	if ($date == '')
	{
		$sql = 'INSERT INTO node (title, type, uid, created, changed) VALUES (\'' . $title . '\', \'' . $type . '\', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())';
	} else {
		$sql = 'INSERT INTO node (title, type, uid, created, changed) VALUES (\'' . $title . '\', \'' . $type . '\', 1, ' . $date . ', ' . 	$date . ')';
	}

	$result = db_query($sql);
	$insert_id = mysql_insert_id();

	$sql = 'INSERT INTO node_revisions (nid, title, uid, body, teaser) VALUES (' . $insert_id . ', \'' . $title . '\', 1, \'' . $body . '\', \'' . $body . '\')';
	$result = db_query($sql);
	$insert_revision_id = mysql_insert_id();

	if ($insert_id > 0)
	{
		$sql = 'UPDATE node SET vid = ' . $insert_revision_id . ' WHERE nid = ' . $insert_id;
		$result = db_query($sql);
	}
}

//example usage of insert_node with a sample content type called 'special'
function insert_special_node()
{
	global $insert_id, $insert_revision_id; //nid and vid
	$content_type = 'special';

	//use mysql_real_escape_string() to clean user text for database insert
	//this is mainly useful when inserting data read from another database query
	$title = mysql_real_escape_string('title');
	$body = mysql_real_escape_string('body text');
	$special_text = mysql_real_escape_string('test');

	insert_node($title, $content_type, $body);

	$sql = 'INSERT INTO content_type_special (vid, nid, field_special_value) VALUES (' . $insert_revision_id . ', ' . $insert_id . ', \'' . $special_text . '\')';

	$result = db_query($sql);
}

Drupal – Replace node link text with image on view

Drupal Views are great for their flexibility and ease of use. It’s often useful to output a teaser with a ‘read more’ link back to the node. Somtimes we need to link to a node from an image instead of text. Drupal doesn’t provide an option for an image link but it’s pretty simple to override the template file. The code below will replace the link text with an image.

Create a new php file in your themes folder with the name of the field view you want to override. In most cases, the name will contain view-node. You can see the theming information by going into the view, and clicking Theme: Information under Basic Settings.
ie. views-view-field–front-blocks–view-node.tpl.php

//output image link instead of text
$field_text = $field->options['text'];
$image_file = '/images/but_' . strtolower($field_text) . '.gif';
$field_image = '<img src="/' . path_to_theme() . $image_file . '" alt="'
. $field_text . '" border="0" />';
$new_output = str_replace($field_text, $field_image, $output);

print $new_output;

Creating random test data

Data Generator 2.0Generating large amounts of test data is a common necessity but doesn’t need to be a painful one. We’ve written several custom solutions in the past but have recently come across a web-based Data Generator that takes this further.

Dummy users, addresses, alpha-numeric values, and strings can be created easily through a form. The program isn’t limited by presets: custom data of almost any type can be defined and randomly created with a few clicks.

Once generated, the data can be exported in a number of useful formats, including SQL, CSV, and XML. You can also save your options for use later on.

There are two options to using the program. It can either be installed directly on a LAMP server or you can set up an account for a fee. It’s released as donationware under a GNU license.


Font Conversion

The Web and Fonts

While fonts are a common and important element of design, translating that concept to the web can sometimes be a challenge. As the web has always had poor font support, there have been a number of ways to work around this. Common solutions are to generate an image using the font, such as with PHP’s GD library or rending a Flash shockwave movie with the font. The problem is that many of these solutions require a specific font format.

While the design world has moved on to the more flexible OpenType format, much of the programming world is using tools that rely on TrueType. Even graphics software giant Adobe has been slow to adopt OpenType in all of its applications, such as Flash CS3 which still only supports TrueType and Type 1.

Enter Font Conversion

Read the rest of this entry »