Index: trunk/wap/hawhaw/hawhaw.inc |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | |
4 | 4 | // HAWHAW: HTML and WML hybrid adapted webserver |
5 | 5 | // PHP class library |
6 | | -// Copyright (C) 2007 Norbert Huffschmid |
7 | | -// Last modified: 4. December 2007 |
| 6 | +// Copyright (C) 2008 Norbert Huffschmid |
| 7 | +// Last modified: 6. April 2008 |
8 | 8 | // |
9 | 9 | // This library is free software; you can redistribute it and/or modify it under the |
10 | 10 | // terms of the GNU Library General Public License as published by the Free Software |
— | — | @@ -20,6 +20,9 @@ |
21 | 21 | // |
22 | 22 | // For further information about this library and its license terms please visit: |
23 | 23 | // http://www.hawhaw.de/ |
| 24 | +// |
| 25 | +// changes against V5.17: |
| 26 | +// - consider additional XHTML devices: Aspen Simulator and Android |
24 | 27 | |
25 | 28 | ################################### |
26 | 29 | # BEGIN OF CONFIGURATION PART # |
— | — | @@ -40,7 +43,7 @@ |
41 | 44 | ################################### |
42 | 45 | |
43 | 46 | // miscellaneous constants |
44 | | -define("HAW_HAW_VERSION", "HAWHAW V5.16"); |
| 47 | +define("HAW_HAW_VERSION", "HAWHAW V5.18B"); |
45 | 48 | define("HAW_COPYRIGHT", "(C) Norbert Huffschmid"); |
46 | 49 | if (defined("HAW_TERA_WURFL_PATH")) |
47 | 50 | define("HAW_VERSION", HAW_HAW_VERSION . "/Tera-WURFL"); |
— | — | @@ -911,8 +914,8 @@ |
912 | 915 | } |
913 | 916 | |
914 | 917 | |
915 | | - /* |
916 | | - Adds a HAW_raw object to HAW_deck. (undocumented feature - for test only!) |
| 918 | + /** |
| 919 | + Adds a HAW_raw object to HAW_deck. |
917 | 920 | @param raw Some HAW_raw object. |
918 | 921 | @see HAW_raw |
919 | 922 | */ |
— | — | @@ -927,30 +930,28 @@ |
928 | 931 | } |
929 | 932 | |
930 | 933 | |
931 | | - /* |
932 | | - Adds some user-defined HAWHAW object to HAW_deck (undocumented feature)<br> |
933 | | - For skilled HAWHAW programmers only! |
| 934 | + /** |
| 935 | + Adds some user-defined HAWHAW object to HAW_deck.<br> |
934 | 936 | @param udef Some user-defined object. |
935 | | - */ |
936 | | - function add_userdefined($udef) |
937 | | - { |
938 | | - /* A user-defined HAWHAW class definition MUST look like this: |
939 | 937 | |
| 938 | + <pre> |
| 939 | + A user-defined HAWHAW class definition should look like this: |
| 940 | + |
940 | 941 | class HAW_foo // some class name of your choice |
941 | 942 | { |
942 | 943 | var $bar; // some class variable declarations of your choice |
943 | 944 | |
944 | 945 | function HAW_foo(...) |
945 | 946 | { |
946 | | - // some constructor code of your choice |
| 947 | + # some constructor code (if required) |
947 | 948 | } |
948 | 949 | |
949 | | - function HAW_boobaz(...) |
| 950 | + function set_bar($bar) |
950 | 951 | { |
951 | | - // as many user-defined functions as needed |
| 952 | + # as many user-defined functions as you need |
952 | 953 | } |
953 | 954 | |
954 | | - // this member function is called by HAWHAW and MUST NOT be changed! |
| 955 | + # this member function is called by HAWHAW and MUST NOT be changed! |
955 | 956 | function get_elementtype() |
956 | 957 | { |
957 | 958 | return HAW_USERDEFINED; |
— | — | @@ -958,23 +959,26 @@ |
959 | 960 | |
960 | 961 | function create($deck) |
961 | 962 | { |
962 | | - // this member function is called by HAWHAW and MUST be present! |
963 | | - // it is in the programmers responsibility what kind of markup is created here! |
964 | | - // you have access to all HAW_deck properties by evaluating $deck |
| 963 | + # this member function is called by HAWHAW and MUST be present! |
| 964 | + # it is in the programmers responsibility what kind of markup is created here! |
| 965 | + # you have access to all HAW_deck properties by evaluating $deck |
965 | 966 | } |
966 | | - } ; |
| 967 | + }; |
967 | 968 | |
968 | | - You have to define this class somewhere after your require("hawhaw.inc") statement |
969 | | - |
970 | 969 | Usage: ... |
| 970 | + require_once("hawhaw.inc); |
| 971 | + require_once("HAW_foo.php"); |
| 972 | + ... |
971 | 973 | $myText = new HAW_text("Classic text"); |
972 | 974 | $myDeck->add_text($myText); |
973 | 975 | $myClass = new HAW_foo("Cool output"); |
974 | | - $myClass->boobaz($ringtone, $sms, $userposition); |
| 976 | + $myClass->set_coolstuff($ringtone, $sms, $userlocation); |
975 | 977 | $myDeck->add_userdefined($myClass); |
976 | 978 | ... |
977 | | - */ |
978 | | - |
| 979 | + </pre> |
| 980 | + */ |
| 981 | + function add_userdefined($udef) |
| 982 | + { |
979 | 983 | if (!is_object($udef)) |
980 | 984 | die("invalid argument in add_userdefined()"); |
981 | 985 | |
— | — | @@ -1602,8 +1606,7 @@ |
1603 | 1607 | |
1604 | 1608 | /** |
1605 | 1609 | Get markup language evaluated for the detected browser. <br> |
1606 | | - (returns <b>int</b> and not <b>void</b>. Must update this documentation tool ...)<br><br> |
1607 | | - Returns:<br> |
| 1610 | + @returns |
1608 | 1611 | - HAW_HTML (HTML)<br> |
1609 | 1612 | - HAW_WML (WML)<br> |
1610 | 1613 | - HAW_HDML (HDML)<br> |
— | — | @@ -1612,10 +1615,10 @@ |
1613 | 1616 | ...<br> |
1614 | 1617 | $myDeck = new HAW_deck();<br> |
1615 | 1618 | if ($myDeck->get_markup_language() == HAW_VXML) {<br> |
1616 | | - // some VoiceXML stuff<br> |
| 1619 | + # some VoiceXML stuff<br> |
1617 | 1620 | }<br> |
1618 | 1621 | else {<br> |
1619 | | - // some visual stuff<br> |
| 1622 | + # some visual stuff<br> |
1620 | 1623 | } |
1621 | 1624 | */ |
1622 | 1625 | function get_markup_language() |
— | — | @@ -2293,16 +2296,20 @@ |
2294 | 2297 | |
2295 | 2298 | function determine_capabilities_generic($HTTP_USER_AGENT, $HTTP_ACCEPT, $HTTP_UA_OS) |
2296 | 2299 | { |
2297 | | - if (strstr(strtolower($HTTP_USER_AGENT), "docomo") || |
2298 | | - strstr(strtolower($HTTP_USER_AGENT), "portalmmm") || |
2299 | | - strstr(strtolower($HTTP_USER_AGENT), "o2imode") || |
2300 | | - strstr(strtolower($HTTP_USER_AGENT), "opera ") || |
2301 | | - strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") || |
2302 | | - strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml")) |
| 2300 | + // make this only once for performance reasons |
| 2301 | + $ua_low = strtolower($HTTP_USER_AGENT); |
| 2302 | + $acc_low = strtolower($HTTP_ACCEPT); |
| 2303 | + |
| 2304 | + if (strstr($ua_low, "docomo") || |
| 2305 | + strstr($ua_low, "portalmmm") || |
| 2306 | + strstr($ua_low, "o2imode") || |
| 2307 | + strstr($ua_low, "opera ") || |
| 2308 | + strstr($ua_low, "reqwirelessweb") || |
| 2309 | + strstr($acc_low, "vnd.wap.xhtml")) |
2303 | 2310 | { |
2304 | 2311 | $this->ml = HAW_HTML; // create HTML (even when device accepts text/vnd.wap.wml too!) |
2305 | 2312 | } |
2306 | | - elseif (strstr(strtolower($HTTP_ACCEPT), "text/vnd.wap.wml")) |
| 2313 | + elseif (strstr($acc_low, "text/vnd.wap.wml")) |
2307 | 2314 | { |
2308 | 2315 | $this->ml = HAW_WML; // create WML |
2309 | 2316 | |
— | — | @@ -2316,25 +2323,25 @@ |
2317 | 2324 | strstr($HTTP_USER_AGENT, "UP.Link")) // Non-UP.Link gateways sometimes have problems! |
2318 | 2325 | $this->owgui_1_3 = true; // device accepts Openwave GUI extensions for WML 1.3 |
2319 | 2326 | } |
2320 | | - elseif (strstr(strtolower($HTTP_ACCEPT), "hdml;version=3.")) // HDML 3.0 and 3.1 |
| 2327 | + elseif (strstr($acc_low, "hdml;version=3.")) // HDML 3.0 and 3.1 |
2321 | 2328 | $this->ml = HAW_HDML; // create HDML |
2322 | | - elseif (strstr(strtolower($HTTP_ACCEPT), "vxml") || // VoiceXML signalled in accept header |
2323 | | - strstr(strtolower($HTTP_ACCEPT), "voicexml") || // alternative accept header |
2324 | | - strstr($HTTP_USER_AGENT, "OpenVXI") || // Speechworks OpenVXI |
2325 | | - strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml") || // PublicVoiceXML voice browser |
2326 | | - strstr(strtolower($HTTP_USER_AGENT), "hastenix") || // hawhaw asterisk adapter |
2327 | | - strstr($HTTP_USER_AGENT, "Tellme")) // Tellme studio voice browser |
| 2329 | + elseif (strstr($acc_low, "vxml") || // VoiceXML signalled in accept header |
| 2330 | + strstr($acc_low, "voicexml") || // alternative accept header |
| 2331 | + strstr($HTTP_USER_AGENT, "OpenVXI") || // Speechworks OpenVXI |
| 2332 | + strstr($ua_low, "publicvoicexml") || // PublicVoiceXML voice browser |
| 2333 | + strstr($ua_low, "hastenix") || // hawhaw asterisk adapter |
| 2334 | + strstr($HTTP_USER_AGENT, "Tellme")) // Tellme studio voice browser |
2328 | 2335 | { |
2329 | 2336 | $this->ml = HAW_VXML; // create VoiceXML |
2330 | 2337 | |
2331 | 2338 | // PublicVoiceXML browser cannot handle <break> elements!!! |
2332 | | - if (strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml")) |
| 2339 | + if (strstr($ua_low, "publicvoicexml")) |
2333 | 2340 | { |
2334 | 2341 | $this->supportsVXMLBreakTag = false; |
2335 | 2342 | } |
2336 | 2343 | |
2337 | 2344 | // detect Motorola VoiceXML platform |
2338 | | - if (strstr(strtolower($HTTP_USER_AGENT), "motorola")) |
| 2345 | + if (strstr($ua_low, "motorola")) |
2339 | 2346 | { |
2340 | 2347 | $this->MotorolaVoiceXML = true; |
2341 | 2348 | } |
— | — | @@ -2343,10 +2350,10 @@ |
2344 | 2351 | { |
2345 | 2352 | if (strstr($HTTP_USER_AGENT, "Mozilla") || |
2346 | 2353 | strstr($HTTP_USER_AGENT, "MSIE") || |
2347 | | - strstr(strtolower($HTTP_USER_AGENT), "lynx") || |
2348 | | - strstr(strtolower($HTTP_USER_AGENT), "avantgo") || |
2349 | | - strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") || |
2350 | | - strstr(strtolower($HTTP_USER_AGENT), "j-")) |
| 2354 | + strstr($ua_low, "lynx") || |
| 2355 | + strstr($ua_low, "avantgo") || |
| 2356 | + strstr($ua_low, "pendragonweb") || |
| 2357 | + strstr($ua_low, "j-")) |
2351 | 2358 | $this->ml = HAW_HTML; // HTML-based browser |
2352 | 2359 | else |
2353 | 2360 | { |
— | — | @@ -2366,9 +2373,10 @@ |
2367 | 2374 | } |
2368 | 2375 | } |
2369 | 2376 | |
2370 | | - if (strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml") || |
2371 | | - strstr(strtolower($HTTP_USER_AGENT), "opera mini") || |
2372 | | - strstr(strtolower($HTTP_USER_AGENT), "google wireless transcoder") || |
| 2377 | + if (strstr($acc_low, "vnd.wap.xhtml") || |
| 2378 | + strstr($ua_low, "opera mini") || |
| 2379 | + strstr($ua_low, "google wireless transcoder") || |
| 2380 | + (strstr($ua_low, "symbianos") && strstr($acc_low, "xhtml+xml")) || |
2373 | 2381 | strstr($HTTP_USER_AGENT, "(iPhone") || |
2374 | 2382 | strstr($HTTP_USER_AGENT, "(iPod") || |
2375 | 2383 | strstr($HTTP_USER_AGENT, "(Aspen Simulator") || |
— | — | @@ -2380,18 +2388,12 @@ |
2381 | 2389 | $this->display_banners = false; |
2382 | 2390 | $this->gif_enabled = true; |
2383 | 2391 | $this->css_enabled = true; |
2384 | | - |
2385 | | - # Hack for iPhone SDK simulator |
2386 | | - # Doesn't seem to like application/vnd.wap.xhtml+xml |
2387 | | - if( strstr($HTTP_USER_AGENT, "(Aspen Simulator") ) { |
2388 | | - $this->xhtmlmp_preferred_mime_type = 'text/html'; |
2389 | | - } |
2390 | 2392 | } |
2391 | | - elseif ( strstr(strtolower($HTTP_USER_AGENT), "avantgo") || |
2392 | | - strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") || |
2393 | | - strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") || |
2394 | | - strstr(strtolower($HTTP_USER_AGENT), "palmos") || |
2395 | | - strstr(strtolower($HTTP_USER_AGENT), "windows ce") || |
| 2393 | + elseif ( strstr($ua_low, "avantgo") || |
| 2394 | + strstr($ua_low, "reqwirelessweb") || |
| 2395 | + strstr($ua_low, "pendragonweb") || |
| 2396 | + strstr($ua_low, "palmos") || |
| 2397 | + strstr($ua_low, "windows ce") || |
2396 | 2398 | strstr(strtolower($HTTP_UA_OS), "windows ce") || |
2397 | 2399 | strstr($HTTP_USER_AGENT, "Mozilla/4.7")) |
2398 | 2400 | { |
— | — | @@ -2400,23 +2402,23 @@ |
2401 | 2403 | $this->pureHTML = false; |
2402 | 2404 | $this->display_banners = false; |
2403 | 2405 | } |
2404 | | - elseif (strstr(strtolower($HTTP_USER_AGENT), "docomo") || |
2405 | | - strstr(strtolower($HTTP_USER_AGENT), "portalmmm") || |
2406 | | - strstr(strtolower($HTTP_USER_AGENT), "o2imode")) |
| 2406 | + elseif (strstr($ua_low, "docomo") || |
| 2407 | + strstr($ua_low, "portalmmm") || |
| 2408 | + strstr($ua_low, "o2imode")) |
2407 | 2409 | { |
2408 | 2410 | // i-mode browser detected |
2409 | 2411 | $this->iModestyle = true; |
2410 | 2412 | $this->pureHTML = false; |
2411 | 2413 | $this->display_banners = false; |
2412 | 2414 | } |
2413 | | - elseif (strstr(strtolower($HTTP_USER_AGENT), "j-")) |
| 2415 | + elseif (strstr($ua_low, "j-")) |
2414 | 2416 | { |
2415 | 2417 | // MML browser detected |
2416 | 2418 | $this->MMLstyle = true; |
2417 | 2419 | $this->pureHTML = false; |
2418 | 2420 | $this->display_banners = false; |
2419 | 2421 | } |
2420 | | - elseif (strstr(strtolower($HTTP_USER_AGENT), "lynx")) |
| 2422 | + elseif (strstr($ua_low, "lynx")) |
2421 | 2423 | { |
2422 | 2424 | // text browser detected |
2423 | 2425 | $this->lynx = true; |
— | — | @@ -2435,18 +2437,19 @@ |
2436 | 2438 | |
2437 | 2439 | // determine if browser is able to display GIF images |
2438 | 2440 | if (($this->ml == HAW_HTML) || |
2439 | | - (strstr(strtolower($HTTP_ACCEPT), "image/gif")) || |
2440 | | - (strstr(strtolower($HTTP_USER_AGENT), "t68"))) |
| 2441 | + (strstr($acc_low, "image/gif")) || |
| 2442 | + (strstr($ua_low, "t68"))) |
2441 | 2443 | $this->gif_enabled = true; // browsers can display GIF |
2442 | 2444 | |
2443 | 2445 | // determine how forms are to be transmitted |
2444 | | - if (strstr(strtolower($HTTP_USER_AGENT), "ericsson") || |
2445 | | - (strstr(strtolower($HTTP_USER_AGENT), "nokia"))) |
| 2446 | + if (strstr($ua_low, "ericsson") || |
| 2447 | + (strstr($ua_low, "nokia"))) |
2446 | 2448 | $this->submitViaLink = true; // with some WAP devices it's quite difficult to submit WML forms |
2447 | 2449 | |
2448 | 2450 | // set alternative mime-type for some XHTML Mobile Profile devices |
2449 | 2451 | if (strstr($HTTP_USER_AGENT, "(iPhone") || |
2450 | | - strstr($HTTP_USER_AGENT, "(iPod")) |
| 2452 | + strstr($HTTP_USER_AGENT, "(iPod") || |
| 2453 | + strstr($HTTP_USER_AGENT, "(Aspen Simulator")) |
2451 | 2454 | $this->xhtmlmp_preferred_mime_type = "text/html"; |
2452 | 2455 | } |
2453 | 2456 | |
— | — | @@ -2768,8 +2771,8 @@ |
2769 | 2772 | } |
2770 | 2773 | |
2771 | 2774 | |
2772 | | - /* |
2773 | | - Adds a HAW_raw object to HAW_form. (undocumented feature - for test only!) |
| 2775 | + /** |
| 2776 | + Adds a HAW_raw object to HAW_form. |
2774 | 2777 | @param raw_markup_object Some HAW_raw object. |
2775 | 2778 | @see HAW_raw |
2776 | 2779 | */ |
— | — | @@ -2784,15 +2787,13 @@ |
2785 | 2788 | } |
2786 | 2789 | |
2787 | 2790 | |
2788 | | - /* |
2789 | | - Adds some user-defined HAWHAW object to HAW_form (undocumented feature)<br> |
2790 | | - For skilled HAWHAW programmers only! |
| 2791 | + /** |
| 2792 | + Adds some user-defined HAWHAW object to HAW_form |
2791 | 2793 | @param udef Some user-defined object. |
| 2794 | + @see HAW_deck::add_userdefined() |
2792 | 2795 | */ |
2793 | 2796 | function add_userdefined($udef) |
2794 | 2797 | { |
2795 | | - // see HAW_deck->add_userdefined($def) for documentation |
2796 | | - |
2797 | 2798 | if (!is_object($udef)) |
2798 | 2799 | die("invalid argument in add_userdefined()"); |
2799 | 2800 | |
— | — | @@ -6259,8 +6260,20 @@ |
6260 | 6261 | |
6261 | 6262 | |
6262 | 6263 | |
6263 | | -/* |
6264 | | - Undocumented class for raw markup insertion - For test only! |
| 6264 | +/** |
| 6265 | + This class allows direct insertion of markup code - Handle with care! |
| 6266 | + <p><b>Example:</b><p> |
| 6267 | + <pre> |
| 6268 | + $myPage = new HAW_deck(...); |
| 6269 | + $pageContent = new HAW_text("Here comes some content ..."); |
| 6270 | + $myPage->add_text($pageContent); |
| 6271 | + $myHtmlCode = "<p>Here comes an adblock for html devices ...</p>"; |
| 6272 | + $myAdBlock = new HAW_raw(HAW_HTML, $myHtmlCode); |
| 6273 | + $myPage->add_raw($myAdblock); |
| 6274 | + $myPage->create_page(); |
| 6275 | + </pre> |
| 6276 | + @see HAW_deck |
| 6277 | + @see HAW_form |
6265 | 6278 | */ |
6266 | 6279 | class HAW_raw |
6267 | 6280 | { |
— | — | @@ -6270,9 +6283,7 @@ |
6271 | 6284 | /** |
6272 | 6285 | Constructor |
6273 | 6286 | @param ml Markup language (HAW_HTML, HAW_WML, HAW_HDML, HAW_VXML). |
6274 | | - @param code Some markup code to be inserted for the selected markup language<br> |
6275 | | - Note: Using this class is for meant for test purposes only. Inproper usage |
6276 | | - can result in highly incompatible applications. |
| 6287 | + @param code Some markup code to be inserted for the selected markup language |
6277 | 6288 | */ |
6278 | 6289 | function HAW_raw($ml,$code) |
6279 | 6290 | { |