Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, October 23, 2006

PHP-Nuke and HawHaw

I wanted to quickly mobile enable a site based on PHP Nuke so I created the following index.wml file:

require_once("mainfile.php");
require("hawhaw.inc.php");
$myPage = new HAW_deck("PSTOIC - The Alumi Association of the Student Television of Imperial College");

$myTitle = new HAW_text("Latest news from PSTOIC", HAW_TEXTFORMAT_BOLD);
$myTitle->set_br(1);
$myPage->add_text($myTitle);

//Example from news/index.php
$result = $db->sql_query("SELECT sid, catid, aid, title, time, hometext, bodytext, comments, counter, topic, informant, notes, acomm, score, ratings FROM ".$prefix."_stories $qdb $querylang ORDER BY sid DESC limit 5");
while ($row = $db->sql_fetchrow($result)) {

$title = filter($row['title'], "nohtml");
$time = $row['time'];
$mobitext = substr(filter($row['hometext'], "nohtml"),0,50);
$myText1 = new HAW_text("* " . $title . " - " . $mobitext );
$myText1->set_br(1);
$myPage->add_text($myText1);

}

$myText1 = new HAW_text("---");
$myText1->set_br(1);
$myPage->add_text($myText1);
$myPage->create_page();

Friday, October 20, 2006

Using HawHaw as a redirect

HawHaw is a toolkit to create universal mobile applications using PHP libraries. It's very good at simplifying the creation of mobile pages for multiple platforms and allows you to preview those pages via your desktop browser which can simplifies testing. For details see www.hawhaw.de

However if you are providing your sites from the same server and want to havesignificantly different sites for your mobile vs. wired users then you don'twant to be limited by the HawHaw emulator for the desktop clients. The following simple approach allows a switch between pages to be made dependanton the client's capabilities. It does not rely on BrowseCap.ini or GetBrowserfunction to work. Thanks to Norbert Huffschmid for explaining what I was doing wrong with my experiments.

1) Create a page for HTML (in my case it was simply the old Index.html) and rename it to index2.html. You can't use index.htm as that would be used first.

2) Create a page for mobiles clients, either manually or via HawHaw. In this case it's called index.wml.php

3) Create a page index.wml as below. This will be the page that all clients will be routed through. It will do a simple detection of the facilities of your browser and switch to the appropriate pages. (see separate article for setting up the index page correctly)


require_once("hawhaw.inc.php");
$myPage = new HAW_deck("Test desk");
if $myPage->ml == HAW_HTML & & $myPage->pureHTML)
{
header("Location: /index2.html");
die;
}
else
{
include "index.wml.php";
}
?>

Thursday, October 19, 2006

Nokia6100 and the Unknown file type

It would appear that the earlier Nokia versions, i.e. my 6100 are not so clever when it comes to detecting what the Web server is sending it. If you give it a .php file then even if Apache is telling you it's of type "text/vnd.wap.wml" then it will error with a cryptic "Unknown file type" message. You need to send .wml files for the phone to be happy.

The work around for this issue is not too complex:

In the .htaccess file you need to add a few lines. The first adds an extra option for the index file.

DirectoryIndex index.wml index.php index.html index.htm

Then we add some code to tell apache to use php to process the index.wml


AddType text/vnd.wap.wml .wml
AddHandler application/x-httpd-php .wml


Finally in the .wml file we put the relavent php code to generate the .wml code for the WAP clients.