XML
|
|
|
|
<? class WMLObj {
function WMLObj($BeginTag,$EndTag)
{
$this->BeginTag=$BeginTag;
$this->EndTag=$EndTag;
$this->Contents=array();
}
function Show()
{
echo $this->BeginTag; if (!$this->BeginTag==""){echo "n";}
foreach($this->Contents as $ind => $val)
{
$this->Contents[$ind]->Show();
}
echo $this->EndTag;if (!$this->EndTag==""){echo "n";}
}
function AddContent(&$Was)
{
$l=count($this->Contents);
$this->Contents[]=&$Was;
return $l;
}
}
class WML extends WMLObj
{
function WML()
{
WMLObj::WMLObj("<?xml version="1.0"?>n<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">n<wml>","</wml>");
}
function Show()
{
header("Content-type: text/vnd.wap.wml"); // Sag dem Browser, dass jetzt WML kommt
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Ein Datum der Vergangenheit um nicht gecached zu werden
header("Last-Modified: " . gmdate("D, d M Y H:i:s"). " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
WMLObj::Show();
}
}
class Head extends WMLObj
{
function Head()
{
WMLObj::WMLObj("<head>","</head>");
$this->AddContent(new Meta("generator","Torben Gerkensmeyers PHP WML Library 1.0"));
}
}
class Meta extends WMLObj
{
function Meta($MName,$MCont)
{
WMLObj::WMLObj("<meta content="".__WMLToUnicode($MCont)."" name="".__WMLToUnicode($MName)."" />","");
}
}
class Template extends WMLObj
{
function Template()
{
WMLObj::WMLObj("<template>","</template>");
}
}
class Card extends WMLObj
{
function Card($ID,$Title, $timer="", $ontimer="",$onenterforward="",$onenterbackward="")
{
$tmp="<card id="".$ID."" title="".$Title.""";
if (!$onenterforward=="") {$tmp=$tmp." onenterforward="".__WMLToUnicode($onenterforward).""";};
if (!$onenterbackward=="") {$tmp=$tmp." onenterbackward="".__WMLToUnicode($onenterbackward).""";};
if (!($timer=="") && !($ontimer=="")) {$tmp=$tmp." ontimer="".__WMLToUnicode($ontimer).""";};
$tmp=$tmp." >";
WMLObj::WMLObj($tmp,"</card>");
if (!($timer=="") && !($ontimer==""))
{
$this->AddContent(new WMLObj("<timer value="".$timer.""/>",""));
}
}
}
class Paragraph extends WMLObj
{
function Paragraph($Align)
{
WMLObj::WMLObj("<p align="".$Align."">","</p>");
}
}
class Text extends WMLObj
{
function Text($Was)
{
WMLObj::WMLObj(__WMLToUnicode($Was),"");
}
}
function __WMLToUnicode ($text) {
for ($i=0;$i<strlen($text);$i++) {
$a=substr($text,$i,1); // Extract each Character
// change special chars above dec 126 to Unicode
if (ord($a) > 126) {
$text = substr_replace ($text, "&#".ord($a).";", $i, 1);
$i=$i+5;
}
// Delete special chars below dec. 32 and above 255
if ((ord($a) < 32) || (ord($a) > 255)) {
$text = substr_replace($text, " ", $i, 1);
}
// Additionally change some other characters
if ( ($a == """) || ($a == "'") || ($a == "<") || ($a == ">") || ($a == "&") ) {
$text = substr_replace ($text, "&#".ord($a).";", $i, 1);
$i=$i+4;
};
if ($a == "$") { // $ must be $$
$text = substr_replace ($text, "$$", $i, 1);
$i=$i+1;
};
}
return $text;
}
class Bold extends WMLObj
{
function Bold()
{
WMLObj::WMLObj("<b>","</b>");
}
}
class Italic extends WMLObj
{
function Italic()
{
WMLObj::WMLObj("<i>","</i>");
}
}
class Link extends WMLObj
{
function Link($Wohin)
{
WMLObj::WMLObj("<a href="".__WMLToUnicode($Wohin)."">","</a>");
}
}
class LineBreak extends WMLObj
{
function LineBreak()
{
WMLObj::WMLObj("<br/>","");
}
}
class Prev extends WMLObj
{
function Prev()
{
WMLObj::WMLObj("<prev/>","");
}
}
class Noop extends WMLObj
{
function Noop()
{
WMLObj::WMLObj("<noop/>","");
}
}
class Refresh extends WMLObj
{
function Refresh()
{
WMLObj::WMLObj("<refresh>","</refresh>");
}
}
class Go extends WMLObj
{
function Go($url,$method="")
{
$tmp="<go href="".__WMLToUnicode($url).""";
if ($method!="") {$tmp=$tmp." method="".$method.""";}
$tmp=$tmp." >";
WMLObj::WMLObj($tmp,"</go>");
}
}
class Postfield extends WMLObj
{
function Postfield($name,$value)
{
WMLObj::WMLObj("<postfield name="".__WMLToUnicode($name)."" value="$value"/>","");
}
}
class Anchor extends WMLObj
{
function Anchor()
{
WMLObj::WMLObj("<anchor>","</anchor>");
}
}
class Setvar extends WMLObj
{
function Setvar($name,$value)
{
WMLObj::WMLObj("<setvar name="".__WMLToUnicode($name)."" value="".__WMLToUnicode($value).""/>","");
}
}
class ButtonDefinition extends WMLObj
{
/* Parameter:
$Button: M�gliche Buttons:
accept : Best�tigung
prev : Zur�ck
help : Hilfeanforderung
reset : Zur�cksetzen von (Formular)Inhalten
delete : L�schen einer Auswahl
$BLabel: Selbstdefinierte Bezeichnung des zu belegenden
Buttons.
$BOptional: ["true"|"false"]: Ist der Button optional?
*/
function ButtonDefinition($Button,$BLabel,$BOptional="false")
{
$tmp="<do type="".$Button.""";
$tmp=$tmp." label="".__WMLToUnicode($BLabel).""";
$tmp=$tmp." optional="".$BOptional.""";
$tmp=$tmp.">";
WMLObj::WMLObj($tmp,"</do>");
}
}
class Image extends WMLObj
{
function Image($URL,$Alt="",$align="",$height="",$width="",$vspace="",$hspace="")
{
$tmp="<img src="".__WMLToUnicode($URL).""";
if (!$Alt=="") {$tmp=$tmp." alt="".__WMLToUnicode($Alt).""";}
if (!$align=="") {$tmp=$tmp." align="".$align.""";}
if (!$height=="") {$tmp=$tmp." height="".$height.""";}
if (!$width=="") {$tmp=$tmp." width="".$width.""";}
if (!$vspace=="") {$tmp=$tmp." vspace="".$vspace.""";}
if (!$hspace=="") {$tmp=$tmp." hspace="".$hspace.""";}
$tmp=$tmp." />";
WMLObj::WMLObj($tmp,"");
}
}
class Select extends WMLObj
{
function Select($title,$name,$iname="",$value="",$multiple="",$tabindex="")
{
$tmp="<select";
if (!$title=="") {$tmp=$tmp." title="".__WMLToUnicode($title).""";}
if (!$name=="") {$tmp=$tmp." name="".__WMLToUnicode($name).""";}
if (!$iname=="") {$tmp=$tmp." iname="".__WMLToUnicode($iname).""";}
if (!$value=="") {$tmp=$tmp." value="".__WMLToUnicode($value).""";}
if (!$multiple=="") {$tmp=$tmp." multiple="".$multiple.""";}
if (!$tabindex=="") {$tmp=$tmp." tabindex="".$tabindex.""";}
$tmp=$tmp." >";
WMLObj::WMLObj($tmp,"</select>");
}
}
class Input extends WMLObj
{
function Input($name,$value="",$size="",$maxlength="",$type="text",$emptyok="true",$tabindex="",$title="")
{
$tmp="<input";
if (!$title=="") {$tmp=$tmp." title="".__WMLToUnicode($title).""";}
if (!$name=="") {$tmp=$tmp." name="".__WMLToUnicode($name).""";}
if (!$value=="") {$tmp=$tmp." value="".__WMLToUnicode($value).""";}
if (!$size=="") {$tmp=$tmp." size="".$size.""";}
if (!$maxlength=="") {$tmp=$tmp." maxlength="".$maxlength.""";}
if (!$type=="") {$tmp=$tmp." type="".$type.""";}
if (!$emptyok=="") {$tmp=$tmp." emptyok="".$emptyok.""";}
if (!$tabindex=="") {$tmp=$tmp." tabindex="".$tabindex.""";}
$tmp=$tmp." />";
WMLObj::WMLObj($tmp,"");
}
}
class Option extends WMLObj
{
function Option($value,$title="",$onpick="")
{
$tmp="<option";
if (!$value=="") {$tmp=$tmp." value="".__WMLToUnicode($value).""";}
if (!$title=="") {$tmp=$tmp." title="".__WMLToUnicode($title).""";}
if (!$onpick=="") {$tmp=$tmp." onpick="".__WMLToUnicode($onpick).""";}
$tmp=$tmp." >";
WMLObj::WMLObj($tmp,"</option>");
}
}
?>
|
|
|
Usage Example
|
<? require_once("wml.inc.php"); $Deck=new WML();
$FirstPage=new Card("Home","Testpage",40,"SecondPage"); //Warps to Testpage in 40 ms $Deck->AddContent($FirstPage);
$InfoParagraph=new Paragraph("left"); $Info=new Text("This is the first TestPage"); $Info2=new LineBreak(); $Info3=new Bold("This text is Fat!"); $Info4=new Text("It can handle the following characters properly: ����"and many others!"); $InfoParagraph->AddContent($Info); $InfoParagraph->AddContent($Info2); $InfoParagraph->AddContent($Info3); $InfoParagraph->AddContent($Info4);
$FirstPage->AddContent($InfoParagraph);
$SecondPage=new Card("SecondPage","SecondPage"); $Deck->AddContent($SecondPage);
$Deck->Show();
?>
-------------------
This gives out:
X-Powered-By: PHP/4.2.1
Content-type: text/vnd.wap.wml
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Fri, 07 Jun 2002 15:02:13 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml>
<card id="Home" title="Testpage" ontimer="SecondPage" >
<timer value="40"/>
<p align="left"> This is the first TestPage <br/>
<b> This one is bold.
</b> It can handle the following characters properly: ääüß"and many others! </p>
</card>
<card id="SecondPage" title="SecondPage" >
</card>
</wml>
|
|
|
Rate This Script
|
|
|
|