<?php
// wml + xhtml style class By Midnex 2007
// Visit my site at http://wap-online.net
// Skype: midnex
// ICQ  : 350-772-392
// Email: midnex@gmail.com

class style {

    var $style;
    var $body = '';

	//This is optional if you want to detect browser in other way, you can write line $style->style = 'wml'; in your index.php to change style
    function style()
	{
	    list($browser) = explode("/", $_SERVER['HTTP_USER_AGENT']);
        $browser_array = array('Mozilla','Opera');
        $style = 0;
	    for($i = 0; $i < count($browser_array); $i++)
	    {
	        if($browser == $browser_array[$i])
	        {
	            $style++;
	        }
	    }
	    if($style == 0)
	    {
			$this->style = 'wml';
	    }
	    else
	    {
        	$this->style = 'xhtml';
	    }
	}

    function add_img($url,$text,$br)
    {
        if($this->style == 'wml')
        {
            $this->body .= '<img src="'.$url.'" alt="'.$text.'"/>';
            if($br)
            {
            	$this->body .= '<br/>';
            }
        }

        if($this->style == 'xhtml')
        {
        	$this->body .= '<img class="no_border" src="'.$url.'" alt="'.$text.'"/>';
	        if($br)
	        {
	        	$this->body .= '<br/>';
	        }
        }
        $this->body .= "\n";
    }
    function start_p($align='left')
    {
    	if($this->style == 'wml')
        {
        	$this->body .= '<p align="'.$align.'">';
        }
        if($this->style == 'xhtml')
        {
        	$this->body .= '<p class="'.$align.'">';
        }
        $this->body .= "\n";
    }
    function end_p()
    {
    	$this->body .= '</p>';
    }
    function start_page($title)
    {
    	if($this->style == 'wml')
        {
        	$this->body .= '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">';
            $this->body .= '<wml><card id="index" title="'.$title.'">';
            $this->body .= "\n";
        }
        if($this->style == 'xhtml')
        {
        	$this->body .= '<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml"><head>
			<title>'.$title.'</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
			</head>
			<body>';
            $this->body .= "\n";
        }
    }

    function end_page()
    {
    	if($this->style == 'wml')
        {
        	$this->body .= '</card></wml>';
        }
        if($this->style == 'xhtml')
        {
        	$this->body .= '</body></html>';
        }
        $this->body .= "\n";
    }

    function headers()
    {
    	if($this->style == 'wml')
        {
            header("Content-type: text/vnd.wap.wml;charset=utf-8");
			header("Cache-Control: no-store, no-cache, must-revalidate");
        }
        if($this->style == 'xhtml')
        {
            header("Content-type: text/html");
			header("Cache-Control: no-store, no-cache, must-revalidate");
    	}
    }

    function add_link($url,$text,$class='title',$br=true)
    {
    	if($this->style == 'wml')
        {
        	$this->body .= '<anchor>'.$text.'<go href="'.$url.'"></go></anchor>';
        }
        if($this->style == 'xhtml')
        {
            if(!empty($class))
            {
            	$this->body .= '<a class="'.$class.'" href="'.$url.'">'.$text.'</a>';
            }
            else
            {
            	$this->body .= '<a href="'.$url.'">'.$text.'</a>';
            }
        }
        if($br)
        {
        	$this->body .= $this->do_br();
        }
        $this->body .= "\n";
    }
    function img_link($url,$img_url,$text,$br)
    {
    	if($this->style == 'wml')
        {
        	$this->body .= '<anchor>';
            $this->body .= $this->add_img($img_url,$text,false);
            $this->body .= '<go href="'.$url.'"></go></anchor>';
            if($br)
            {
            	$this->body .= '<br/>';
            }
        }
        if($this->style == 'xhtml')
        {
        	$this->body .= '<a href="'.$url.'">';
            $this->body .= $this->add_img($img_url,$text,false);
            $this->body .= '</a>';
	        if($br)
	        {
	        	$this->body .= '<br/>';
	        }
        }
        $this->body .= "\n";
    }
    function do_br($sk=1)
    {
    	$this->body .= str_repeat('<br/>',$sk);
    }
    function simple_text($text,$br=false)
    {
    	$this->body .= $text;
        if($br)
        {
        	$this->body .= $this->do_br();
        }
        $this->body .= "\n";
    }
    function show_body()
    {
    	echo $this->body;
    }
}
?>