TeraWurfl
[ class tree: TeraWurfl ] [ index: TeraWurfl ] [ all elements ]

Source for file WurflSupport.php

Documentation is available at WurflSupport.php

  1. <?php
  2. /**
  3.  * Tera_WURFL - PHP MySQL driven WURFL
  4.  * 
  5.  * Tera-WURFL was written by Steve Kamerman, and is based on the
  6.  * Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
  7.  * This version uses a MySQL database to store the entire WURFL file, multiple patch
  8.  * files, and a persistent caching mechanism to provide extreme performance increases.
  9.  * 
  10.  * @package TeraWurfl
  11.  * @author Steve Kamerman <stevekamerman AT gmail.com>
  12.  * @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
  13.  * @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
  14.  */
  15. /**
  16.  * Provides static supporting functions for Tera-WURFL
  17.  * @package TeraWurfl
  18.  *
  19.  */
  20. class WurflSupport{
  21.     
  22.     public $errors;
  23.     /**
  24.      * The HTTP Headers that Tera-WURFL will look through to find the best User Agent, if one is not specified
  25.      * @var Array 
  26.      */
  27.     public static $userAgentHeaders array(
  28.         'HTTP_X_DEVICE_USER_AGENT',
  29.         'HTTP_X_ORIGINAL_USER_AGENT',
  30.         'HTTP_X_OPERAMINI_PHONE_UA',
  31.         'HTTP_X_SKYFIRE_PHONE',
  32.         'HTTP_X_BOLT_PHONE_UA',
  33.         'HTTP_USER_AGENT'
  34.     );
  35.     
  36.     // Constructor
  37.     public function __construct(){
  38.         $this->errors = array();
  39.     }
  40.     
  41.     // Public Methods
  42.     public static function getUserAgent($source=null){
  43.         if(is_null($source|| !is_array($source))$source $_SERVER;
  44.         $userAgent '';
  45.         if(isset($_GET['UA'])){
  46.             $userAgent $_GET['UA'];
  47.         }else{
  48.             foreach(self::$userAgentHeaders as $header){
  49.                 if(array_key_exists($header,$source&& $source[$header]){
  50.                     $userAgent $source[$header];
  51.                     break;
  52.                 }
  53.             }
  54.         }
  55.         return $userAgent;
  56.     }
  57.     
  58.     public static function getAcceptHeader($source=null){
  59.         if(is_null($source|| !is_array($source))$source $_SERVER;
  60.         if(isset($_GET['ACCEPT'])){
  61.             return $_GET['ACCEPT'];
  62.         }else{
  63.             return $source['HTTP_ACCEPT'];
  64.         }
  65.     }
  66.     
  67.     public static function getUAProfile(){
  68.         return isset($_SERVER['X-WAP-PROFILE'])?$_SERVER['X-WAP-PROFILE']:'';
  69.     }
  70.     
  71.     public static function formatBytes($bytes){
  72.         $unim array("B","KB","MB","GB","TB","PB");
  73.         $c 0;
  74.         while ($bytes>=1024{
  75.             $c++;
  76.             $bytes $bytes/1024;
  77.         }
  78.         return number_format($bytes,($c 0),".",",")." ".$unim[$c];
  79.     }
  80.     public static function formatBitrate($bytes,$seconds){
  81.         $unim array("bps","Kbps","Mbps","Gbps","Tbps","Pbps");
  82.         $bits $bytes 8;
  83.         $bps $bits $seconds;
  84.         $c 0;
  85.         while ($bps>=1000{
  86.             $c++;
  87.             $bps $bps/1000;
  88.         }
  89.         return number_format($bps,($c 0),".",",")." ".$unim[$c];
  90.     }
  91.     public static function showBool($var){
  92.         if($var === true)return("true");
  93.         if($var === false)return("false");
  94.         return($var);
  95.     }
  96.     public static function showLogLevel($num){
  97.         $log_arr array(1=>"LOG_CRIT",4=>"LOG_ERR",5=>"LOG_WARNING",6=>"LOG_NOTICE");
  98.         return($log_arr[$num]);
  99.     }
  100. }

Documentation generated on Sun, 19 Sep 2010 00:16:09 +0000 by phpDocumentor 1.4.3