r32858 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32857‎ | r32858 | r32859 >
Date:17:23, 6 April 2008
Author:nhuffschmid
Status:old
Tags:
Comment:
merge with hawhaw V5.17 (Brion's enhancements will become part of next official hawhaw release, thanks :)
Modified paths:
  • /trunk/wap/hawhaw/hawhaw.inc (modified) (history)

Diff [purge]

Index: trunk/wap/hawhaw/hawhaw.inc
@@ -2,8 +2,8 @@
33
44 // HAWHAW: HTML and WML hybrid adapted webserver
55 // 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
88 //
99 // This library is free software; you can redistribute it and/or modify it under the
1010 // terms of the GNU Library General Public License as published by the Free Software
@@ -20,6 +20,9 @@
2121 //
2222 // For further information about this library and its license terms please visit:
2323 // http://www.hawhaw.de/
 24+//
 25+// changes against V5.17:
 26+// - consider additional XHTML devices: Aspen Simulator and Android
2427
2528 ###################################
2629 # BEGIN OF CONFIGURATION PART #
@@ -40,7 +43,7 @@
4144 ###################################
4245
4346 // miscellaneous constants
44 -define("HAW_HAW_VERSION", "HAWHAW V5.16");
 47+define("HAW_HAW_VERSION", "HAWHAW V5.18B");
4548 define("HAW_COPYRIGHT", "(C) Norbert Huffschmid");
4649 if (defined("HAW_TERA_WURFL_PATH"))
4750 define("HAW_VERSION", HAW_HAW_VERSION . "/Tera-WURFL");
@@ -911,8 +914,8 @@
912915 }
913916
914917
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.
917920 @param raw Some HAW_raw object.
918921 @see HAW_raw
919922 */
@@ -927,30 +930,28 @@
928931 }
929932
930933
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>
934936 @param udef Some user-defined object.
935 - */
936 - function add_userdefined($udef)
937 - {
938 - /* A user-defined HAWHAW class definition MUST look like this:
939937
 938+ <pre>
 939+ A user-defined HAWHAW class definition should look like this:
 940+
940941 class HAW_foo // some class name of your choice
941942 {
942943 var $bar; // some class variable declarations of your choice
943944
944945 function HAW_foo(...)
945946 {
946 - // some constructor code of your choice
 947+ # some constructor code (if required)
947948 }
948949
949 - function HAW_boobaz(...)
 950+ function set_bar($bar)
950951 {
951 - // as many user-defined functions as needed
 952+ # as many user-defined functions as you need
952953 }
953954
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!
955956 function get_elementtype()
956957 {
957958 return HAW_USERDEFINED;
@@ -958,23 +959,26 @@
959960
960961 function create($deck)
961962 {
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
965966 }
966 - } ;
 967+ };
967968
968 - You have to define this class somewhere after your require("hawhaw.inc") statement
969 -
970969 Usage: ...
 970+ require_once("hawhaw.inc);
 971+ require_once("HAW_foo.php");
 972+ ...
971973 $myText = new HAW_text("Classic text");
972974 $myDeck->add_text($myText);
973975 $myClass = new HAW_foo("Cool output");
974 - $myClass->boobaz($ringtone, $sms, $userposition);
 976+ $myClass->set_coolstuff($ringtone, $sms, $userlocation);
975977 $myDeck->add_userdefined($myClass);
976978 ...
977 - */
978 -
 979+ </pre>
 980+ */
 981+ function add_userdefined($udef)
 982+ {
979983 if (!is_object($udef))
980984 die("invalid argument in add_userdefined()");
981985
@@ -1602,8 +1606,7 @@
16031607
16041608 /**
16051609 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
16081611 - HAW_HTML (HTML)<br>
16091612 - HAW_WML (WML)<br>
16101613 - HAW_HDML (HDML)<br>
@@ -1612,10 +1615,10 @@
16131616 ...<br>
16141617 $myDeck = new HAW_deck();<br>
16151618 if ($myDeck->get_markup_language() == HAW_VXML) {<br>
1616 - // some VoiceXML stuff<br>
 1619+ # some VoiceXML stuff<br>
16171620 }<br>
16181621 else {<br>
1619 - // some visual stuff<br>
 1622+ # some visual stuff<br>
16201623 }
16211624 */
16221625 function get_markup_language()
@@ -2293,16 +2296,20 @@
22942297
22952298 function determine_capabilities_generic($HTTP_USER_AGENT, $HTTP_ACCEPT, $HTTP_UA_OS)
22962299 {
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"))
23032310 {
23042311 $this->ml = HAW_HTML; // create HTML (even when device accepts text/vnd.wap.wml too!)
23052312 }
2306 - elseif (strstr(strtolower($HTTP_ACCEPT), "text/vnd.wap.wml"))
 2313+ elseif (strstr($acc_low, "text/vnd.wap.wml"))
23072314 {
23082315 $this->ml = HAW_WML; // create WML
23092316
@@ -2316,25 +2323,25 @@
23172324 strstr($HTTP_USER_AGENT, "UP.Link")) // Non-UP.Link gateways sometimes have problems!
23182325 $this->owgui_1_3 = true; // device accepts Openwave GUI extensions for WML 1.3
23192326 }
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
23212328 $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
23282335 {
23292336 $this->ml = HAW_VXML; // create VoiceXML
23302337
23312338 // PublicVoiceXML browser cannot handle <break> elements!!!
2332 - if (strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml"))
 2339+ if (strstr($ua_low, "publicvoicexml"))
23332340 {
23342341 $this->supportsVXMLBreakTag = false;
23352342 }
23362343
23372344 // detect Motorola VoiceXML platform
2338 - if (strstr(strtolower($HTTP_USER_AGENT), "motorola"))
 2345+ if (strstr($ua_low, "motorola"))
23392346 {
23402347 $this->MotorolaVoiceXML = true;
23412348 }
@@ -2343,10 +2350,10 @@
23442351 {
23452352 if (strstr($HTTP_USER_AGENT, "Mozilla") ||
23462353 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-"))
23512358 $this->ml = HAW_HTML; // HTML-based browser
23522359 else
23532360 {
@@ -2366,9 +2373,10 @@
23672374 }
23682375 }
23692376
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")) ||
23732381 strstr($HTTP_USER_AGENT, "(iPhone") ||
23742382 strstr($HTTP_USER_AGENT, "(iPod") ||
23752383 strstr($HTTP_USER_AGENT, "(Aspen Simulator") ||
@@ -2380,18 +2388,12 @@
23812389 $this->display_banners = false;
23822390 $this->gif_enabled = true;
23832391 $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 - }
23902392 }
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") ||
23962398 strstr(strtolower($HTTP_UA_OS), "windows ce") ||
23972399 strstr($HTTP_USER_AGENT, "Mozilla/4.7"))
23982400 {
@@ -2400,23 +2402,23 @@
24012403 $this->pureHTML = false;
24022404 $this->display_banners = false;
24032405 }
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"))
24072409 {
24082410 // i-mode browser detected
24092411 $this->iModestyle = true;
24102412 $this->pureHTML = false;
24112413 $this->display_banners = false;
24122414 }
2413 - elseif (strstr(strtolower($HTTP_USER_AGENT), "j-"))
 2415+ elseif (strstr($ua_low, "j-"))
24142416 {
24152417 // MML browser detected
24162418 $this->MMLstyle = true;
24172419 $this->pureHTML = false;
24182420 $this->display_banners = false;
24192421 }
2420 - elseif (strstr(strtolower($HTTP_USER_AGENT), "lynx"))
 2422+ elseif (strstr($ua_low, "lynx"))
24212423 {
24222424 // text browser detected
24232425 $this->lynx = true;
@@ -2435,18 +2437,19 @@
24362438
24372439 // determine if browser is able to display GIF images
24382440 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")))
24412443 $this->gif_enabled = true; // browsers can display GIF
24422444
24432445 // 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")))
24462448 $this->submitViaLink = true; // with some WAP devices it's quite difficult to submit WML forms
24472449
24482450 // set alternative mime-type for some XHTML Mobile Profile devices
24492451 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"))
24512454 $this->xhtmlmp_preferred_mime_type = "text/html";
24522455 }
24532456
@@ -2768,8 +2771,8 @@
27692772 }
27702773
27712774
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.
27742777 @param raw_markup_object Some HAW_raw object.
27752778 @see HAW_raw
27762779 */
@@ -2784,15 +2787,13 @@
27852788 }
27862789
27872790
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
27912793 @param udef Some user-defined object.
 2794+ @see HAW_deck::add_userdefined()
27922795 */
27932796 function add_userdefined($udef)
27942797 {
2795 - // see HAW_deck->add_userdefined($def) for documentation
2796 -
27972798 if (!is_object($udef))
27982799 die("invalid argument in add_userdefined()");
27992800
@@ -6259,8 +6260,20 @@
62606261
62616262
62626263
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
62656278 */
62666279 class HAW_raw
62676280 {
@@ -6270,9 +6283,7 @@
62716284 /**
62726285 Constructor
62736286 @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
62776288 */
62786289 function HAW_raw($ml,$code)
62796290 {

Status & tagging log