HAWHAW Plugin Development

HAWHAW

HAWHAW provides a flexible plugin mechanism that allows to add new functionality without the need to mess around with the internals of the hawhaw.inc PHP library. As HAWHAW is OpenSource, it is an option to hack some application-specific enhancements directly into the hawhaw.inc file. But as these enhancements must be merged all the time into updated hawhaw.inc versions, this approach seems not to be the preferred one.

This article shows how a new "list" feature can be added to HAWHAW by means of the plugin mechanism.


HAWHAW Plugin Basics

Plugins are integrated into HAWHAW's object model with the HAW_deck::add_plugin() function.

A plugin module contains the plugin class with an arbitrary name. It can contain member functions as much as required by the plugin's functionality, but at least the following 2 ones:

function get_elementtype()
{
  return HAW_PLUGIN;
}

function create($deck)
{
  # plugin-specific code ...
}
Given that you have written some plugin "foo": This is how you have to add your plugin within your HAWHAW deck:
require_once("hawhaw.inc);
require_once("HAW_plugin_foo.php");
...       
$myClass = new HAW_plugin_foo("Cool output");
$myClass->set_coolstuff($ringtone, $sms, $userlocation);
$myDeck->add_userdefined($myClass);
...

But let's take a look at the "list" example in order to see how things work in detail.


HAWHAW plugin: HAW_plugin_list

Screenshot of a deck containing lists

The application code that creates this output goes like this:


The plugin code HAW_plugin_list.php is shown here:


The plugin code is rather self-explanatory. The $items array stores all the list items and is filled by the add_item() function. The create() function contains all the markup output for different browser types.

If different output is required for various browser types, the get_markup_language() function call is helpful.


CSS Finetuning and Conclusion

CSS Finetuning

Maybe you have observed the following function call in the application code:

$myDeck->set_css("listdemo.css"); // do some css magic

A simple CSS file listdemo.css like this ...

ul { list-style-image:url(../images/star.gif) }
ol { list-style-type: upper-roman }

... allows to show some fancy list style on CSS-capable devices.


This plugin demo application is accessable under the following URL: http://www.hawhaw.de/articles/lists/demo/listdemo.php. Feel free to visit it with you mobile device and see how the plugin's code is rendered there.

You have seen how simple it is to write plugins. The place to share your HAWHAW plugins with the world is:

http://groups.yahoo.com/group/hawhaw/


Keep on laughing!