WAP: Part 5 - Customizing content with WURFL
We've covered (in-depth) the delivery side of getting URLs to phones using Kannel. Now it's time to cover the content you'd like to
display on the phone. One tool that I've found to be the best single database of what phones can do is the WURFL. WURFL stands for Wireless Universal Resource File, and it is simply and XML 'database' of phones, their families, and their capabilities. You can get the XML file here. There's also a WURLF PHP toolkit for incorporating the WURFL into your project, download it here.
To start, unzip the wurfl toolkit and then download the wurfl file and unzip it as well. Then set up the WURFL config file and update the
WURFL cache.
wurfl_config.php
To build the cache, run update_cache.php.
If you're planning on running update_cache.php from a web browser after periodically updating wurfl.xml, you may want to change
permissions so they're apache friendly:
WURFL and the toolkit simply work by analizing the User-Agent header to determine what type of device is connecting and what capabilities it has. The cache groups phone families logically so it only loads a portion of the WURFL database... only that which is needed. It also stores device info from previously connected devices, to negate the need of an additional lookup in the future.
Here is a simple example of using the WURFL to determine if the "device" is a WAP browser (a phone) or not (a full-fledged browser
such as IE or Firefox).
Note that many "smart" phones will not return TRUE for 'browser_is_wap'. You may or may not want to send them to a full-sized site due to screen size, download speeds, etc. There is a boatload of additional information that can be gleamed from the WURFL PHP toolkit from inspecting the $device->capabilities array.
For determining content format, as I see it you have 3 basic choices:
There are other capabilities such as 'flash_lite' which I will not get into as I'm focusing on the lowest common denominator of phone, hoping to deliver the most content quickly, easily, and reliably.
Another thing to consider that is not neccessarily dependent on the format is the screen size. I used $device->capabilities['display']['max_image_width'] and 'max_image_height' to scale images to the phone's screen. You can also use the $device->capabilities['image_format'] array to determine what type (jpg, gif, wbmp, etc.) of images the phone can display.
In my next article I'll talk about the ups and downs of microbrowser content in WML / XHTML MP.
WAP: Part 1 - MultiTech USB GPRS Modem in Linux
WAP: Part 2 - Send SMS from Kannel
WAP: Part 3 - WAP Push with Kannel & PHP
WAP: Part 4 - Send SMS from PHP
WAP: Part 5 - Customizing content with WURFL
WAP: Part 6 - Microbrowser content in WML / XHTML MP
display on the phone. One tool that I've found to be the best single database of what phones can do is the WURFL. WURFL stands for Wireless Universal Resource File, and it is simply and XML 'database' of phones, their families, and their capabilities. You can get the XML file here. There's also a WURLF PHP toolkit for incorporating the WURFL into your project, download it here.
Installing and Configuring the WURFL
To start, unzip the wurfl toolkit and then download the wurfl file and unzip it as well. Then set up the WURFL config file and update the
WURFL cache.
/ $ cd
~ $ mkdir -p ~/src/wurfl
~ $ cd ~/src/wurfl
~/src/wurfl $ wget http://downloads.sourceforge.net/wurfl/wurfl_php_tools_21.zip
~/src/wurfl $ unzip wurfl_php_tools_21.zip
~/src/wurfl $ wget http://wurfl.sourceforge.net/wurfl.zip
~/src/wurfl $ unzip wurfl.zip
~/src/wurfl $ vi wurfl_config.php
wurfl_config.php
<?php
...
define("DATADIR", dirname(__FILE__));
define("WURFL_PARSER_FILE", DATADIR . 'wurfl_parser.php');
define("WURFL_CLASS_FILE", DATADIR . 'wurfl_class.php');
...
?>
Updating the cache
To build the cache, run update_cache.php.
~/src/wurfl $ php update_cache.php
If you're planning on running update_cache.php from a web browser after periodically updating wurfl.xml, you may want to change
permissions so they're apache friendly:
/ # cd <wurfl dir>
wurfl # chown -R :apache .
wurfl # chmod 664 cache.php
wurfl # chmod 2775 .
wurfl # sudo -u apache php ./update_cache.php
WURFL and the toolkit simply work by analizing the User-Agent header to determine what type of device is connecting and what capabilities it has. The cache groups phone families logically so it only loads a portion of the WURFL database... only that which is needed. It also stores device info from previously connected devices, to negate the need of an additional lookup in the future.
Using the WURFL
Here is a simple example of using the WURFL to determine if the "device" is a WAP browser (a phone) or not (a full-fledged browser
such as IE or Firefox).
<?php
require_once 'wurfl_config.php';
require_once WURFL_CLASS_FILE;
//new up the wurfl class
$device = new wurfl_class();
//have it load it's information based on the user agent
$device->GetDeviceCapabilitiesFromAgent($_SERVER['HTTP_USER_AGENT']);
if(!$device->browser_is_wap)
{
header('Location: http://www.yahoo.com');
exit;
}
?>
Note that many "smart" phones will not return TRUE for 'browser_is_wap'. You may or may not want to send them to a full-sized site due to screen size, download speeds, etc. There is a boatload of additional information that can be gleamed from the WURFL PHP toolkit from inspecting the $device->capabilities array.
For determining content format, as I see it you have 3 basic choices:
- Full-fledged pages displayed by smart phones or "big" browsers (from above example)
- XHTML Mobile Profile (MP), determined by $device->capabilities['markup']['preferred_markup'] = 'html_wi_oma_xhtmlmp_1_0'
- WML, determined by $device->capabilities['markup']['preferred_markup'] = 'wml_1_1'
There are other capabilities such as 'flash_lite' which I will not get into as I'm focusing on the lowest common denominator of phone, hoping to deliver the most content quickly, easily, and reliably.
Another thing to consider that is not neccessarily dependent on the format is the screen size. I used $device->capabilities['display']['max_image_width'] and 'max_image_height' to scale images to the phone's screen. You can also use the $device->capabilities['image_format'] array to determine what type (jpg, gif, wbmp, etc.) of images the phone can display.
In my next article I'll talk about the ups and downs of microbrowser content in WML / XHTML MP.
Articles In This Series:
WAP: Part 1 - MultiTech USB GPRS Modem in Linux
WAP: Part 2 - Send SMS from Kannel
WAP: Part 3 - WAP Push with Kannel & PHP
WAP: Part 4 - Send SMS from PHP
WAP: Part 5 - Customizing content with WURFL
WAP: Part 6 - Microbrowser content in WML / XHTML MP
