Location: PHPKode > scripts > Wapple Architect Mobilization > wapple-architect-mobilization/wapl.php
<?php 
/**
 * Wapple Architect WAPL Wrapper class
 * 
 * This class provides an interface into the waplBuilder and waplComms classes.
 * It does error handling and allows configuration of the operation of the other classes.
 * 
 * @author Rich Gubby
 * @version 1.0
 * @package WappleArchitect
 */
class wapl
{

	/**
	 * Store the builder classes
	 * 
	 * @access public
	 * @var object
	 */
	public $builder;
	
	/**
	 * Store the communication class
	 * 
	 * @access public
	 * @var object
	 */
	private $comms;
	
	/**
	 * Are we in debug mode - cookies don't get set if you are
	 * 
	 * @access public
	 * @var boolean
	 */
	public $debugMode = false;
	
	/**
	 * Use cookies to remember mobile detection
	 * 
	 * @access public
	 * @var boolean
	 */
	public $useCookies = true;
	
	/**
	 * Developer key
	 * 
	 * @access public
	 * @var string
	 */
	public $devKey = '';
	
	/**
	 * Store error messages
	 * 
	 * @access public
	 * @var array
	 */
	public $errorMessage = array('comms' => array(), 'builder' => array());
	
	/**
	 * Constructor class
	 * 
	 * @access public
	 * @return void
	 */
	public function __construct()
	{
		require_once('wapl_builder.php');
		require_once('wapl_comms.php');
		
		$this->builder = new waplBuilder($this);
		$this->comms = new waplComms($this);
		
		// Check if we've got an error in setup
		if($this->getErrorMessage('comms'))
		{
			unset($this->comms);
		}
	}
	
	/**
	 * Set the developer key
	 * 
	 * @param string $devKey
	 * @access public
	 * @return void
	 */
	public function setDevKey($devKey)
	{
		$this->devKey = $devKey;
	}
	
	/**
	 * Set the debug mode
	 * 
	 * @param boolean $debugMode
	 * @access public
	 * @return void
	 */
	public function setDebugMode($debugMode)
	{
		$this->debugMode = $debugMode;
	}
	
	/**
	 * Use cookies or not
	 * 
	 * @param boolean $useCookies
	 * @access public
	 * @return void
	 */
	public function useCookies($useCookies)
	{
		$this->useCookies = $useCookies;
	}
	
	/**
	 * Set a cookie
	 * @param boolean $value
	 * @access public
	 * @return void
	 */
	public function setCookie($value)
	{
		if(!$this->debugMode)
		{
			setcookie("isMobile", $value, time()+3600);
		}
	}
	
	/**
	 * Get any error messages
	 * 
	 * @param string $type
	 * @access public
	 * @return string
	 */
	public function getErrorMessage($type = '')
	{
		if(isset($type) AND $type != '')
		{
			return implode('. ', $this->errorMessage[$type]);
		}
		
		$string = '';
		foreach($this->errorMessage as $key => $val)
		{
			$string .= implode('. ', $val);
		}
		return $string;
	}
	
	/**
	 * Wrapper for checking mobile device
	 * 
	 * @access public
	 * @return boolean
	 */
	public function isMobileDevice()
	{
		if(isset($this->comms))
		{
			return $this->comms->isMobileDevice();
		}
		return false;
	}
	
	/**
	 * Wrapper for getting a mobile device
	 *
	 * @access public
	 * @return mixed
	 */
	public function getMobileDevice()
	{
		if(isset($this->comms))
		{
			return $this->comms->getMobileDevice($url);
		}
		return false;
	}	
	
	/**
	 * Wrapper for getting markup from WAPL
	 * 
	 * @param string $wapl
	 * @access public
	 * @return mixed
	 */
	public function getMarkupFromWapl($wapl)
	{
		if(isset($this->comms))
		{
			return $this->comms->getMarkupFromWapl($wapl);
		}
		return false;
	}

	/**
	 * Wrapper for displaying markup from WAPL
	 * 
	 * @param string $wapl
	 * @access public
	 * @return mixed
	 */
	public function displayMarkupFromWapl($wapl)
	{
		if(isset($this->comms))
		{
			return $this->comms->displayMarkupFromWapl($wapl);
		}
		return false;
	}
	
	/**
	 * Wrapper for getting markup from URL
	 * 
	 * @param string $url
	 * @access public
	 * @return mixed
	 */
	public function getMarkupFromUrl($url)
	{
		if(isset($this->comms))
		{
			return $this->comms->getMarkupFromUrl($url);
		}
		return false;
	}
	
	/**
	 * Wrapper for displaying markup from URL
	 * 
	 * @param string $url
	 * @access public
	 * @return mixed
	 */
	public function displayMarkupFromUrl($url)
	{
		if(isset($this->comms))
		{
			return $this->comms->displayMarkupFromUrl($url);
		}
		return false;
	}
}
?>
Return current item: Wapple Architect Mobilization