This article covers the basics of how the wap theme works with the accessibility module. The guide does not cover the functions that are used to make the output correctly formatted into WML compliant code. This will be covered in another article.
page.tpl.php is missing many of the core variables that are available because I feel they are unnecessary for a mobile device. Some of these features also hard to correct due to the limitations of wireless mark-up language itself. The basic page.tpl.php is shown below.
<?php print $dtd ?>
<wml>
<template>
<do cardname="a1" cardtype="accept" cardlabel="Sections">
<go href="#primary" />
</do>
<?php if (isset($secondary_links)) { ?>
<do cardname="a2" cardtype="accept" cardlabel="Pages">
<go href="#secondary" />
</do>
<?php } ?>
</template>
<card cardid="main" cardtitle="<?php print $site_name; ?>">
<?php if ($site_name) { ?>
<p><big><strong><em><a accesskey="0" href="<?php print $base_path ?>"><?php print $site_name; ?></a>
<?php if ($site_slogan) { ?><br /><?php print $site_slogan; ?><?php } ?>
</em></strong></big></p>
<?php } ?>
<?php if ($title) { ?><p><em><?php print $title; ?></em></p><?php } ?>
<?php print $content; ?>
</card>
<?php if (isset($primary_links)) { ?>
<card cardid="primary" cardtitle="Sections">
<?php print theme('links', $primary_links, array('class' => 'menu p')) ?>
</card>
<?php } ?>
<?php if (isset($secondary_links)) { ?>
<card cardid="secondary" cardtitle="Pages">
<?php print theme('links', $secondary_links, array('class' => 'menu s')) ?>
</card>
<?php } ?>
</wml>
The template creates 3 cards. One card for the main content, and two additional cards for menus.
Things to note here are that cardid, cardtitle and cardlabel are not valid WML tags. They are corrected on rendering as the accessibility module tries to convert HTML code into WML. title, label and id are stripped from tag attributes as they are invalid WML syntax.
Also, the $logo variable, amongst others, is not shown. The theme() function can be found in accessibility module files.
As with the other page.tpl.php previewed on this site, $dtd is created through the template.php file. This is just the XML and doc type declaration.
<?php
function phptemplate_comment_post_forbidden($nid) {
global $user;
if ($user->uid) {
return t("you can't post comments");
}
else {
// we cannot use drupal_get_destination() because these links sometimes appear on /node and taxo listing pages
if (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
$destination = "destination=". drupal_urlencode("comment/reply/$nid#comment_form");
}
else {
$destination = "destination=". drupal_urlencode("node/$nid#comment_form");
}
return t('Please visit the site on a PC to comment!');
}
}
function _phptemplate_variables($hook, $vars) {
global $accessibility, $mime, $locale, $xml, $user;
if (!@$accessibility) {
$content_type = 0;
} else {
$content_type = $accessibility['content_type'];
}
switch($hook) {
case 'page' :
if ( module_exists('accessibility') ) {
$output = '';
$xmlns = '';
if ( in_array($content_type, $mime['xml']) ){
$output .= $xml;
$xmlns .= 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="'. $locale .'" ';
}
$output .= $mime['dtds'][$content_type];
$vars['dtd'] = $output;
$vars['xmlns'] = $xmlns;
} else {
$vars['dtd'] = '<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">'."\n";
$vars['xmlns'] = '';
}
break;
}
return $vars;
}
A custom message for comments posting is also found in this file. It can be removed from the template if required, but the current version of the accessibility module forbids posting and login by mobile users. I may be changing this feature in future releases.
* Note: If you are using Drupal version 4.7x then you need to change module_exists to module_exist as this was a change moving to version 5.
Comments
WAP
Your module works perfect! No problems at all with the mobi theme. However, I'm stuck with the WAP version. When I try a WAP emulator such as Waptiger or Wapsilon, then they load the normal html template. For some reason WAP browsers aren't recognized and/or the WAP template isn't loaded..
Using the 5.x version.
Maybe not in the list
Firstly, thanks.
Off hand, I cannot remember the headers that these tools send.
Need to check the browser.txt fiel if the UA string is in the list for these.
If you know the UA, can you post them?
Br
Jamie
Mobile Movie Database
aha...
Hi Jamie, quick reply!
Now that you mentioned it... the UA appears to be "WapTiger/5.0 (http://www.waptiger.com/ ()" - which of course no real WAP mobile would use. Hehe ;)
Guess I'll have to buy a real WAP capable phone to test this.
Thanks for the repy anyway. Like I said, I did manage my mhtml mobi site with your module, excellent work.
It isn't on the list
Just checked the UA of Wapsilon:
It starts "waps", so just add it to the browser text include file
and "wapt" if you want too.
Thanks for checking though, it has been a while, and to be honest,
I was not that bothered about the old WAP anyway..
Br
Jamie
Mobile Movie Database