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

Source for file EZweb.php

Documentation is available at EZweb.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3.  
  4. /**
  5.  * PHP versions 4 and 5
  6.  *
  7.  * Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>,
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions are met:
  12.  *
  13.  *     * Redistributions of source code must retain the above copyright
  14.  *       notice, this list of conditions and the following disclaimer.
  15.  *     * Redistributions in binary form must reproduce the above copyright
  16.  *       notice, this list of conditions and the following disclaimer in the
  17.  *       documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29.  * POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * @category   Networking
  32.  * @package    Net_UserAgent_Mobile
  33.  * @author     KUBO Atsuhiro <kubo@iteman.jp>
  34.  * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
  35.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  36.  * @version    CVS: $Id: EZweb.php,v 1.1 2009/05/26 08:48:16 kuboa Exp $
  37.  * @link       http://www.au.kddi.com/ezfactory/tec/spec/4_4.html
  38.  * @link       http://www.au.kddi.com/ezfactory/tec/spec/new_win/ezkishu.html
  39.  * @since      File available since Release 0.1.0
  40.  */
  41.  
  42. require_once 'Net/UserAgent/Mobile/Common.php';
  43. require_once 'Net/UserAgent/Mobile/Display.php';
  44.  
  45. // {{{ Net_UserAgent_Mobile_EZweb
  46.  
  47. /**
  48.  * EZweb implementation
  49.  *
  50.  * Net_UserAgent_Mobile_EZweb is a subclass of {@link Net_UserAgent_Mobile_Common},
  51.  * which implements EZweb (WAP1.0/2.0) user agents.
  52.  *
  53.  * SYNOPSIS:
  54.  * <code>
  55.  * require_once 'Net/UserAgent/Mobile.php';
  56.  *
  57.  * $_SERVER['HTTP_USER_AGENT'] = 'UP.Browser/3.01-HI02 UP.Link/3.2.1.2';
  58.  * $agent = &Net_UserAgent_Mobile::factory();
  59.  *
  60.  * printf("Name: %s\n", $agent->getName()); // 'UP.Browser'
  61.  * printf("Version: %s\n", $agent->getVersion()); // 3.01
  62.  * printf("DeviceID: %s\n", $agent->getDeviceID()); // 'HI02'
  63.  * printf("Server: %s\n", $agent->getServer()); // 'UP.Link/3.2.1.2'
  64.  *
  65.  * e.g.) 'UP.Browser/3.01-HI02 UP.Link/3.2.1.2 (Google WAP Proxy/1.0)'
  66.  * printf("Comment: %s\n", $agent->getComment()); // 'Google WAP Proxy/1.0'
  67.  *
  68.  * e.g.) 'KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1'
  69.  * if ($agent->isXHTMLCompliant()) {
  70.  *     print "XHTML compliant!\n"; // true
  71.  * }
  72.  * </code>
  73.  *
  74.  * @category   Networking
  75.  * @package    Net_UserAgent_Mobile
  76.  * @author     KUBO Atsuhiro <kubo@iteman.jp>
  77.  * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
  78.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  79.  * @version    Release: 1.0.0
  80.  * @link       http://www.au.kddi.com/ezfactory/tec/spec/4_4.html
  81.  * @link       http://www.au.kddi.com/ezfactory/tec/spec/new_win/ezkishu.html
  82.  * @since      Class available since Release 0.1.0
  83.  */
  84. {
  85.  
  86.     // {{{ properties
  87.  
  88.     /**#@+
  89.      * @access public
  90.      */
  91.  
  92.     /**#@-*/
  93.  
  94.     /**#@+
  95.      * @access private
  96.      */
  97.  
  98.     /**
  99.      * server string like 'UP.Link/3.2.1.2'
  100.      * @var string 
  101.      */
  102.     var $_serverName '';
  103.  
  104.     /**
  105.      * comment like 'Google WAP Proxy/1.0'
  106.      * @var string 
  107.      */
  108.     var $_comment = null;
  109.  
  110.     /**
  111.      * whether it's XHTML compliant or not
  112.      * @var boolean 
  113.      */
  114.     var $_xhtmlCompliant = false;
  115.  
  116.     /**#@-*/
  117.  
  118.     /**#@+
  119.      * @access public
  120.      */
  121.  
  122.     // }}}
  123.     // {{{ isEZweb()
  124.  
  125.     /**
  126.      * returns true
  127.      *
  128.      * @return boolean 
  129.      */
  130.     function isEZweb()
  131.     {
  132.         return true;
  133.     }
  134.  
  135.     // }}}
  136.     // {{{ isTUKa()
  137.  
  138.     /**
  139.      * returns true if the agent is TU-Ka
  140.      *
  141.      * @return boolean 
  142.      */
  143.     function isTUKa()
  144.     {
  145.         $tuka substr($this->_rawModel21);
  146.         if ($this->isWAP2()) {
  147.             if ($tuka == 'U'{
  148.                 return true;
  149.             }
  150.         else {
  151.             if ($tuka == 'T'{
  152.                 return true;
  153.             }
  154.         }
  155.         
  156.         return false;
  157.     }
  158.  
  159.     // }}}
  160.     // {{{ parse()
  161.  
  162.     /**
  163.      * Parses HTTP_USER_AGENT string.
  164.      *
  165.      * @param string $userAgent User-Agent string
  166.      */
  167.     function parse($userAgent)
  168.     {
  169.         if (preg_match('/^KDDI-(.*)/'$userAgent$matches)) {
  170.  
  171.             // KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1
  172.             $this->_xhtmlCompliant = true;
  173.             @list($this->_rawModel$browser$opt$this->_serverName=
  174.                 explode(' '$matches[1]4);
  175.             @list($this->name$versionexplode('/'$browser);
  176.             $this->version = "$version $opt";
  177.         else {
  178.  
  179.             // UP.Browser/3.01-HI01 UP.Link/3.4.5.2
  180.             @list($browser$this->_serverName$comment=
  181.                 explode(' '$userAgent3);
  182.             @list($this->name$softwareexplode('/'$browser);
  183.             @list($this->version$this->_rawModelexplode('-'$software);
  184.             if ($comment{
  185.                 $this->_comment preg_replace('/^\((.*)\)$/''$1'$comment);
  186.             }
  187.         }
  188.     }
  189.  
  190.     // }}}
  191.     // {{{ makeDisplay()
  192.  
  193.     /**
  194.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  195.      *
  196.      * @return Net_UserAgent_Mobile_Display 
  197.      */
  198.     function makeDisplay()
  199.     {
  200.         @list($width$height=
  201.             explode(','$this->getHeader('X-UP-DEVCAP-SCREENPIXELS'));
  202.         $screenDepth explode(','$this->getHeader('X-UP-DEVCAP-SCREENDEPTH'));
  203.         $depth $screenDepth[0pow(2(integer)$screenDepth[0]: 0;
  204.         $color $this->getHeader('X-UP-DEVCAP-ISCOLOR'=== '1' ? true : false;
  205.         return new Net_UserAgent_Mobile_Display(array('width'  => $width,
  206.                                                       'height' => $height,
  207.                                                       'color'  => $color,
  208.                                                       'depth'  => $depth)
  209.                                                 );
  210.     }
  211.  
  212.     // }}}
  213.     // {{{ getDeviceID()
  214.  
  215.     /**
  216.      * Returns the device ID of the user agent.
  217.      *
  218.      * @return string 
  219.      */
  220.     function getDeviceID()
  221.     {
  222.         return $this->_rawModel;
  223.     }
  224.  
  225.     // }}}
  226.     // {{{ getServer()
  227.  
  228.     /**
  229.      * returns server string like 'UP.Link/3.2.1.2'
  230.      *
  231.      * @return string 
  232.      */
  233.     function getServer()
  234.     {
  235.         return $this->_serverName;
  236.     }
  237.  
  238.     // }}}
  239.     // {{{ getComment()
  240.  
  241.     /**
  242.      * returns comment like 'Google WAP Proxy/1.0'. returns null if nothinng.
  243.      *
  244.      * @return boolean 
  245.      */
  246.     function getComment()
  247.     {
  248.         return $this->_comment;
  249.     }
  250.  
  251.     // }}}
  252.     // {{{ isXHTMLCompliant()
  253.  
  254.     /**
  255.      * returns whether it's XHTML compliant or not
  256.      *
  257.      * @return boolean 
  258.      */
  259.     function isXHTMLCompliant()
  260.     {
  261.         return $this->_xhtmlCompliant;
  262.     }
  263.  
  264.     // }}}
  265.     // {{{ getCarrierShortName()
  266.  
  267.     /**
  268.      * returns the short name of the carrier
  269.      *
  270.      * @return string 
  271.      */
  272.     function getCarrierShortName()
  273.     {
  274.         return 'E';
  275.     }
  276.  
  277.     // }}}
  278.     // {{{ getCarrierLongName()
  279.  
  280.     /**
  281.      * returns the long name of the carrier
  282.      *
  283.      * @return string 
  284.      */
  285.     function getCarrierLongName()
  286.     {
  287.         return 'EZweb';
  288.     }
  289.  
  290.     // }}}
  291.     // {{{ isWIN()
  292.  
  293.     /**
  294.      * Returns whether the agent is CDMA 1X WIN or not.
  295.      *
  296.      * @return boolean 
  297.      */
  298.     function isWIN()
  299.     {
  300.         return substr($this->_rawModel21== 3 ? true : false;
  301.     }
  302.  
  303.     // }}}
  304.     // {{{ getUID()
  305.  
  306.     /**
  307.      * Gets the UID of a subscriber.
  308.      *
  309.      * @return string 
  310.      * @since Method available since Release 1.0.0RC1
  311.      */
  312.     function getUID()
  313.     {
  314.         if (array_key_exists('HTTP_X_UP_SUBNO'$_SERVER)) {
  315.             return $_SERVER['HTTP_X_UP_SUBNO'];
  316.         }
  317.     }
  318.  
  319.     /**#@-*/
  320.  
  321.     /**#@+
  322.      * @access private
  323.      */
  324.  
  325.     /**#@-*/
  326.  
  327.     // }}}
  328. }
  329.  
  330. // }}}
  331.  
  332. /*
  333.  * Local Variables:
  334.  * mode: php
  335.  * coding: iso-8859-1
  336.  * tab-width: 4
  337.  * c-basic-offset: 4
  338.  * c-hanging-comment-ender-p: nil
  339.  * indent-tabs-mode: nil
  340.  * End:
  341.  */

Documentation generated on Tue, 23 Jun 2009 10:00:04 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.