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

Source for file Vodafone.php

Documentation is available at Vodafone.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: KUBO Atsuhiro <kubo@isite.co.jp>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Vodafone.php,v 1.2 2005/02/01 04:46:38 kuboa Exp $
  20. //
  21.  
  22. require_once(dirname(__FILE__'/Common.php');
  23. require_once(dirname(__FILE__'/Display.php');
  24.  
  25. /**
  26.  * Vodafone implementation
  27.  *
  28.  * Net_UserAgent_Mobile_Vodafone is a subclass of
  29.  * {@link Net_UserAgent_Mobile_Common}, which implements Vodafone user agents.
  30.  *
  31.  * SYNOPSIS:
  32.  * <code>
  33.  * require_once('Net/UserAgent/Mobile.php');
  34.  *
  35.  * $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
  36.  * $agent = &Net_UserAgent_Mobile::factory();
  37.  *
  38.  * printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
  39.  * printf("Version: %s\n", $agent->getVersion()); // 2.0
  40.  * printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
  41.  * if ($agent->isPacketCompliant()) {
  42.  *     print "Packet is compliant.\n"; // false
  43.  * }
  44.  *
  45.  * // only availabe in Java compliant
  46.  * // e.g.) 'J-PHONE/4.0/J-SH51/SNXXXXXXXXX SH/0001a Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0'
  47.  * printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
  48.  * printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
  49.  * printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
  50.  *
  51.  * $info = $agent->getJavaInfo();  // array
  52.  * foreach ($info as $key => $value) {
  53.  *     print "$key: $value\n";
  54.  * }
  55.  * </code>
  56.  *
  57.  * @package  Net_UserAgent_Mobile
  58.  * @category Networking
  59.  * @author   KUBO Atsuhiro <kubo@isite.co.jp>
  60.  * @access   public
  61.  * @version  $Revision: 1.2 $
  62.  * @see      Net_UserAgent_Mobile_Common
  63.  * @link     http://developers.vodafone.jp/dp/tool_dl/web/useragent.php
  64.  * @link     http://developers.vodafone.jp/dp/tool_dl/web/position.php
  65.  */
  66. {
  67.  
  68.     // {{{ properties
  69.  
  70.     /**#@+
  71.      * @access private
  72.      */
  73.  
  74.     /**
  75.      * name of the model like 'J-DN02'
  76.      * @var string 
  77.      */
  78.     var $_model '';
  79.  
  80.     /**
  81.      * whether the agent is packet connection complicant or not
  82.      * @var boolean 
  83.      */
  84.     var $_packetCompliant = false;
  85.  
  86.     /**
  87.      * terminal unique serial number
  88.      * @var string 
  89.      */
  90.     var $_serialNumber = null;
  91.  
  92.     /**
  93.      * vendor code like 'SH'
  94.      * @var string 
  95.      */
  96.     var $_vendor '';
  97.  
  98.     /**
  99.      * vendor version like '0001a'
  100.      * @var string 
  101.      */
  102.     var $_vendorVersion = null;
  103.  
  104.     /**
  105.      * Java profiles
  106.      * @var array 
  107.      */
  108.     var $_javaInfo = array();
  109.  
  110.     /**
  111.      * whether the agent is 3G
  112.      * @var boolean 
  113.      */
  114.     var $_is3G = true;
  115.  
  116.     /**#@-*/
  117.  
  118.     /**#@+
  119.      * @access public
  120.      */
  121.  
  122.     // }}}
  123.     // {{{ isJPhone()
  124.  
  125.     /**
  126.      * returns true
  127.      *
  128.      * @return boolean 
  129.      */
  130.     function isJPhone()
  131.     {
  132.         return true;
  133.     }
  134.  
  135.     // }}}
  136.     // {{{ isVodafone()
  137.  
  138.     /**
  139.      * returns true
  140.      *
  141.      * @return boolean 
  142.      */
  143.     function isVodafone()
  144.     {
  145.         return true;
  146.     }
  147.  
  148.     // }}}
  149.     // {{{ parse()
  150.  
  151.     /**
  152.      * parse HTTP_USER_AGENT string
  153.      *
  154.      * @return mixed void, or a PEAR error object on error
  155.      */
  156.     function parse()
  157.     {
  158.         $agent explode(' '$this->getUserAgent());
  159.         preg_match('!(?:(^Vodafone)|(^J-PHONE)|(^MOT-))!'$agent[0],
  160.                    $matches
  161.                    );
  162.         $class @$matches[1'Vodafone' :
  163.             (@$matches[2'J-PHONE' 'Motorola');
  164.         $result = true;
  165.  
  166.         switch ($class{
  167.         case 'Vodafone':
  168.             $result $this->_parseVodafone($agent);
  169.             break;
  170.         case 'J-PHONE':
  171.             $result $this->_parseJphone($agent);
  172.             break;
  173.         case 'Motorola':
  174.             $result $this->_parseMotorola($agent);
  175.             break;
  176.         default:
  177.             break;
  178.         }
  179.  
  180.         if (Net_UserAgent_Mobile::isError($result)) {
  181.             return $result;
  182.         }
  183.     }
  184.  
  185.     // }}}
  186.     // {{{ makeDisplay()
  187.  
  188.     /**
  189.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  190.      *
  191.      * @return object newly created {@link Net_UserAgent_Mobile_Display}
  192.      *      object
  193.      * @see Net_UserAgent_Mobile_Display
  194.      */
  195.     function makeDisplay(
  196.     {
  197.         @list($width$height=
  198.             explode('*'$this->getHeader('x-jphone-display'));
  199.         $color = false;
  200.         $depth = 0;
  201.         if ($color_string $this->getHeader('x-jphone-color')) {
  202.             preg_match('!^([CG])(\d+)$!'$color_string$matches);
  203.             $color $matches[1=== 'C' ? true : false;
  204.             $depth $matches[2];
  205.         }
  206.         return new Net_UserAgent_Mobile_Display(array(
  207.                                                       'width'  => $width,
  208.                                                       'height' => $height,
  209.                                                       'depth'  => $depth,
  210.                                                       'color'  => $color)
  211.                                                 );
  212.     }
  213.  
  214.     // }}}
  215.     // {{{ getModel()
  216.  
  217.     /**
  218.      * returns name of the model like 'J-DN02'
  219.      *
  220.      * @return string 
  221.      */
  222.     function getModel()
  223.     {
  224.         return $this->_model;
  225.     }
  226.  
  227.     // }}}
  228.     // {{{ isPacketCompliant()
  229.  
  230.     /**
  231.      * returns whether the agent is packet connection complicant or not
  232.      *
  233.      * @return boolean 
  234.      */
  235.     function isPacketCompliant()
  236.     {
  237.         return $this->_packetCompliant;
  238.     }
  239.  
  240.     // }}}
  241.     // {{{ getSerialNumber()
  242.  
  243.     /**
  244.      * return terminal unique serial number. returns null if user forbids to
  245.      * send his/her serial number.
  246.      *
  247.      * @return string 
  248.      */
  249.     function getSerialNumber()
  250.     {
  251.         return $this->_serialNumber;
  252.     }
  253.  
  254.     // }}}
  255.     // {{{ getVendor()
  256.  
  257.     /**
  258.      * returns vendor code like 'SH'
  259.      *
  260.      * @return string 
  261.      */
  262.     function getVendor()
  263.     {
  264.         return $this->_vendor;
  265.     }
  266.  
  267.     // }}}
  268.     // {{{ getVendorVersion()
  269.  
  270.     /**
  271.      * returns vendor version like '0001a'. returns null if unknown.
  272.      *
  273.      * @return string 
  274.      */
  275.     function getVendorVersion()
  276.     {
  277.         return $this->_vendorVersion;
  278.     }
  279.  
  280.     // }}}
  281.     // {{{ getJavaInfo()
  282.  
  283.     /**
  284.      * returns array of Java profiles
  285.      *
  286.      * Array structure is something like:
  287.      *
  288.      * - 'Profile'       => 'MIDP-1.0',
  289.      * - 'Configuration' => 'CLDC-1.0',
  290.      * - 'Ext-Profile'   => 'JSCL-1.1.0'
  291.      *
  292.      * @return array 
  293.      */
  294.     function getJavaInfo()
  295.     {
  296.         return $this->_javaInfo;
  297.     }
  298.  
  299.     // }}}
  300.     // {{{ getCarrierShortName()
  301.  
  302.     /**
  303.      * returns the short name of the carrier
  304.      *
  305.      * @return string 
  306.      */
  307.     function getCarrierShortName()
  308.     {
  309.         return 'V';
  310.     }
  311.  
  312.     // }}}
  313.     // {{{ getCarrierLongName()
  314.  
  315.     /**
  316.      * returns the long name of the carrier
  317.      *
  318.      * @return string 
  319.      */
  320.     function getCarrierLongName()
  321.     {
  322.         return 'Vodafone';
  323.     }
  324.  
  325.     // }}}
  326.     // {{{ isTypeC()
  327.  
  328.     /**
  329.      * returns true if the type is C
  330.      *
  331.      * @return boolean 
  332.      */
  333.     function isTypeC()
  334.     {
  335.         if ($this->_is3G || !preg_match('!^[32]\.!'$this->version)) {
  336.             return false;
  337.         }
  338.  
  339.         return true;
  340.     }
  341.  
  342.     // }}}
  343.     // {{{ isTypeP()
  344.  
  345.     /**
  346.      * returns true if the type is P
  347.      *
  348.      * @return boolean 
  349.      */
  350.     function isTypeP()
  351.     {
  352.         if ($this->_is3G || !preg_match('!^4\.!'$this->version)) {
  353.             return false;
  354.         }
  355.  
  356.         return true;
  357.     }
  358.  
  359.     // }}}
  360.     // {{{ isTypeW()
  361.  
  362.     /**
  363.      * returns true if the type is W
  364.      *
  365.      * @return boolean 
  366.      */
  367.     function isTypeW()
  368.     {
  369.         if ($this->_is3G || !preg_match('!^5\.!'$this->version)) {
  370.             return false;
  371.         }
  372.  
  373.         return true;
  374.     }
  375.  
  376.     // }}}
  377.     // {{{ isType3GC()
  378.  
  379.     /**
  380.      * returns true if the type is 3GC
  381.      *
  382.      * @return boolean 
  383.      */
  384.     function isType3GC()
  385.     {
  386.         return $this->_is3G;
  387.     }
  388.  
  389.     /**#@-*/
  390.  
  391.     /**#@+
  392.      * @access private
  393.      */
  394.  
  395.     // }}}
  396.     // {{{ _parseVodafone()
  397.  
  398.     /**
  399.      * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
  400.      *
  401.      * @param array $agent parts of the User-Agent string
  402.      * @return mixed void, or a PEAR error object on error
  403.      */
  404.     function _parseVodafone(&$agent)
  405.     {
  406.         $count count($agent);
  407.         $this->_packetCompliant = true;
  408.  
  409.         // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  410.         // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  411.         // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  412.         @list($this->name$this->version$this->_model$modelVersion,
  413.               $serialNumberexplode('/'$agent[0]);
  414.         if ($serialNumber{
  415.             if ($serialNumber{
  416.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  417.                     return $this->noMatch();
  418.                 }
  419.                 $this->_serialNumber $matches[1];
  420.             }
  421.         }
  422.  
  423.         if (!preg_match('!^([a-z]+)([a-z]\d{3})$!i'$modelVersion$matches)
  424.             {
  425.             return $this->noMatch();
  426.         }
  427.         $this->_vendor $matches[1];
  428.         $this->_vendorVersion $matches[2];
  429.  
  430.         for ($i = 2; $i $count; ++$i{
  431.             list($key$valueexplode('/'$agent[$i]);
  432.             $this->_javaInfo[$key$value;
  433.         }
  434.     }
  435.  
  436.     // }}}
  437.     // {{{ _parseJphone()
  438.  
  439.     /**
  440.      * parse HTTP_USER_AGENT string for the ancient agent
  441.      *
  442.      * @param array $agent parts of the User-Agent string
  443.      * @return mixed void, or a PEAR error object on error
  444.      */
  445.     function _parseJphone(&$agent)
  446.     {
  447.         $count count($agent);
  448.         $this->_is3G = false;
  449.  
  450.         if ($count > 1{
  451.  
  452.             // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
  453.             $this->_packetCompliant = true;
  454.             @list($this->name$this->version$this->_model,
  455.                   $serialNumberexplode('/'$agent[0]);
  456.             if ($serialNumber{
  457.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  458.                     return $this->noMatch();
  459.                 }
  460.                 $this->_serialNumber $matches[1];
  461.             }
  462.             list($this->_vendor$this->_vendorVersion=
  463.                 explode('/'$agent[1]);
  464.             for ($i = 2; $i $count; ++$i{
  465.                 list($key$valueexplode('/'$agent[$i]);
  466.                 $this->_javaInfo[$key$value;
  467.             }
  468.         else {
  469.  
  470.             // J-PHONE/2.0/J-DN02
  471.             @list($this->name$this->version$model=
  472.                 explode('/'$agent[0]);
  473.             $this->_model  = (string)$model;
  474.             if ($this->_model{
  475.                 preg_match('!J-([A-Z]+)!'$this->_model$matches);
  476.                 $this->_vendor $matches[1];
  477.             }
  478.         }
  479.     }
  480.  
  481.     // }}}
  482.     // {{{ _parseMotorola()
  483.  
  484.     /**
  485.      * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
  486.      *
  487.      * @param array $agent parts of the User-Agent string
  488.      * @return mixed void, or a PEAR error object on error
  489.      */
  490.     function _parseMotorola(&$agent)
  491.     {
  492.         $count count($agent);
  493.         $this->_packetCompliant = true;
  494.         $this->_vendor 'MOT';
  495.  
  496.         // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  497.         list($name$this->_vendorVersionexplode('/'$agent[0]);
  498.         $this->_model substr(strrchr($name'-')1);
  499.  
  500.         for ($i = 2; $i $count; ++$i{
  501.             list($key$valueexplode('/'$agent[$i]);
  502.             $this->_javaInfo[$key$value;
  503.         }
  504.     }
  505.  
  506.     /**#@-*/
  507. }
  508.  
  509. /*
  510.  * Local Variables:
  511.  * mode: php
  512.  * coding: iso-8859-1
  513.  * tab-width: 4
  514.  * c-basic-offset: 4
  515.  * c-hanging-comment-ender-p: nil
  516.  * indent-tabs-mode: nil
  517.  * End:
  518.  */
  519. ?>

Documentation generated on Mon, 11 Mar 2019 14:22:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.