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.5 2005/08/04 05:36:19 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.5 $
  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.      * the name of the mobile phone
  118.      * @var string 
  119.      */
  120.     var $_msname '';
  121.  
  122.     /**#@-*/
  123.  
  124.     /**#@+
  125.      * @access public
  126.      */
  127.  
  128.     // }}}
  129.     // {{{ isJPhone()
  130.  
  131.     /**
  132.      * returns true
  133.      *
  134.      * @return boolean 
  135.      */
  136.     function isJPhone()
  137.     {
  138.         return true;
  139.     }
  140.  
  141.     // }}}
  142.     // {{{ isVodafone()
  143.  
  144.     /**
  145.      * returns true
  146.      *
  147.      * @return boolean 
  148.      */
  149.     function isVodafone()
  150.     {
  151.         return true;
  152.     }
  153.  
  154.     // }}}
  155.     // {{{ parse()
  156.  
  157.     /**
  158.      * parse HTTP_USER_AGENT string
  159.      *
  160.      * @return mixed void, or a PEAR error object on error
  161.      */
  162.     function parse()
  163.     {
  164.         $agent explode(' '$this->getUserAgent());
  165.         preg_match('!(?:(^Vodafone)|(^J-PHONE)|(^MOT-))!'$agent[0],
  166.                    $matches
  167.                    );
  168.         $class @$matches[1'Vodafone' :
  169.             (@$matches[2'J-PHONE' 'Motorola');
  170.         $result = true;
  171.  
  172.         switch ($class{
  173.         case 'Vodafone':
  174.             $result $this->_parseVodafone($agent);
  175.             break;
  176.         case 'J-PHONE':
  177.             $result $this->_parseJphone($agent);
  178.             break;
  179.         case 'Motorola':
  180.             $result $this->_parseMotorola($agent);
  181.             break;
  182.         default:
  183.             break;
  184.         }
  185.  
  186.         if (Net_UserAgent_Mobile::isError($result)) {
  187.             return $result;
  188.         }
  189.  
  190.  
  191.         $this->_msname $this->getHeader('x-jphone-msname');
  192.     }
  193.  
  194.     // }}}
  195.     // {{{ makeDisplay()
  196.  
  197.     /**
  198.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  199.      *
  200.      * @return object newly created {@link Net_UserAgent_Mobile_Display}
  201.      *      object
  202.      * @see Net_UserAgent_Mobile_Display
  203.      */
  204.     function makeDisplay(
  205.     {
  206.         @list($width$height=
  207.             explode('*'$this->getHeader('x-jphone-display'));
  208.         $color = false;
  209.         $depth = 0;
  210.         if ($color_string $this->getHeader('x-jphone-color')) {
  211.             preg_match('!^([CG])(\d+)$!'$color_string$matches);
  212.             $color $matches[1=== 'C' ? true : false;
  213.             $depth $matches[2];
  214.         }
  215.         return new Net_UserAgent_Mobile_Display(array(
  216.                                                       'width'  => $width,
  217.                                                       'height' => $height,
  218.                                                       'depth'  => $depth,
  219.                                                       'color'  => $color)
  220.                                                 );
  221.     }
  222.  
  223.     // }}}
  224.     // {{{ getModel()
  225.  
  226.     /**
  227.      * returns name of the model like 'J-DN02'
  228.      *
  229.      * @return string 
  230.      */
  231.     function getModel()
  232.     {
  233.         return $this->_model;
  234.     }
  235.  
  236.     // }}}
  237.     // {{{ isPacketCompliant()
  238.  
  239.     /**
  240.      * returns whether the agent is packet connection complicant or not
  241.      *
  242.      * @return boolean 
  243.      */
  244.     function isPacketCompliant()
  245.     {
  246.         return $this->_packetCompliant;
  247.     }
  248.  
  249.     // }}}
  250.     // {{{ getSerialNumber()
  251.  
  252.     /**
  253.      * return terminal unique serial number. returns null if user forbids to
  254.      * send his/her serial number.
  255.      *
  256.      * @return string 
  257.      */
  258.     function getSerialNumber()
  259.     {
  260.         return $this->_serialNumber;
  261.     }
  262.  
  263.     // }}}
  264.     // {{{ getVendor()
  265.  
  266.     /**
  267.      * returns vendor code like 'SH'
  268.      *
  269.      * @return string 
  270.      */
  271.     function getVendor()
  272.     {
  273.         return $this->_vendor;
  274.     }
  275.  
  276.     // }}}
  277.     // {{{ getVendorVersion()
  278.  
  279.     /**
  280.      * returns vendor version like '0001a'. returns null if unknown.
  281.      *
  282.      * @return string 
  283.      */
  284.     function getVendorVersion()
  285.     {
  286.         return $this->_vendorVersion;
  287.     }
  288.  
  289.     // }}}
  290.     // {{{ getJavaInfo()
  291.  
  292.     /**
  293.      * returns array of Java profiles
  294.      *
  295.      * Array structure is something like:
  296.      *
  297.      * - 'Profile'       => 'MIDP-1.0',
  298.      * - 'Configuration' => 'CLDC-1.0',
  299.      * - 'Ext-Profile'   => 'JSCL-1.1.0'
  300.      *
  301.      * @return array 
  302.      */
  303.     function getJavaInfo()
  304.     {
  305.         return $this->_javaInfo;
  306.     }
  307.  
  308.     // }}}
  309.     // {{{ getCarrierShortName()
  310.  
  311.     /**
  312.      * returns the short name of the carrier
  313.      *
  314.      * @return string 
  315.      */
  316.     function getCarrierShortName()
  317.     {
  318.         return 'V';
  319.     }
  320.  
  321.     // }}}
  322.     // {{{ getCarrierLongName()
  323.  
  324.     /**
  325.      * returns the long name of the carrier
  326.      *
  327.      * @return string 
  328.      */
  329.     function getCarrierLongName()
  330.     {
  331.         return 'Vodafone';
  332.     }
  333.  
  334.     // }}}
  335.     // {{{ isTypeC()
  336.  
  337.     /**
  338.      * returns true if the type is C
  339.      *
  340.      * @return boolean 
  341.      */
  342.     function isTypeC()
  343.     {
  344.         if ($this->_is3G || !preg_match('!^[32]\.!'$this->version)) {
  345.             return false;
  346.         }
  347.  
  348.         return true;
  349.     }
  350.  
  351.     // }}}
  352.     // {{{ isTypeP()
  353.  
  354.     /**
  355.      * returns true if the type is P
  356.      *
  357.      * @return boolean 
  358.      */
  359.     function isTypeP()
  360.     {
  361.         if ($this->_is3G || !preg_match('!^4\.!'$this->version)) {
  362.             return false;
  363.         }
  364.  
  365.         return true;
  366.     }
  367.  
  368.     // }}}
  369.     // {{{ isTypeW()
  370.  
  371.     /**
  372.      * returns true if the type is W
  373.      *
  374.      * @return boolean 
  375.      */
  376.     function isTypeW()
  377.     {
  378.         if ($this->_is3G || !preg_match('!^5\.!'$this->version)) {
  379.             return false;
  380.         }
  381.  
  382.         return true;
  383.     }
  384.  
  385.     // }}}
  386.     // {{{ isType3GC()
  387.  
  388.     /**
  389.      * returns true if the type is 3GC
  390.      *
  391.      * @return boolean 
  392.      */
  393.     function isType3GC()
  394.     {
  395.         return $this->_is3G;
  396.     }
  397.  
  398.     // }}}
  399.     // {{{ getMsname()
  400.  
  401.     /**
  402.      * returns the name of the mobile phone
  403.      *
  404.      * @return string the name of the mobile phone
  405.      */
  406.     function getMsname()
  407.     {
  408.         return $this->_msname;
  409.     }
  410.  
  411.     /**#@-*/
  412.  
  413.     /**#@+
  414.      * @access private
  415.      */
  416.  
  417.     // }}}
  418.     // {{{ _parseVodafone()
  419.  
  420.     /**
  421.      * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
  422.      *
  423.      * @param array $agent parts of the User-Agent string
  424.      * @return mixed void, or a PEAR error object on error
  425.      */
  426.     function _parseVodafone(&$agent)
  427.     {
  428.         $count count($agent);
  429.         $this->_packetCompliant = true;
  430.  
  431.         // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  432.         // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  433.         // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  434.         @list($this->name$this->version$this->_model$modelVersion,
  435.               $serialNumberexplode('/'$agent[0]);
  436.         if ($serialNumber{
  437.             if ($serialNumber{
  438.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  439.                     return $this->noMatch();
  440.                 }
  441.                 $this->_serialNumber $matches[1];
  442.             }
  443.         }
  444.  
  445.         if (!preg_match('!^([a-z]+)([a-z]\d{3})$!i'$modelVersion$matches)
  446.             {
  447.             return $this->noMatch();
  448.         }
  449.         $this->_vendor $matches[1];
  450.         $this->_vendorVersion $matches[2];
  451.  
  452.         for ($i = 2; $i $count; ++$i{
  453.             list($key$valueexplode('/'$agent[$i]);
  454.             $this->_javaInfo[$key$value;
  455.         }
  456.     }
  457.  
  458.     // }}}
  459.     // {{{ _parseJphone()
  460.  
  461.     /**
  462.      * parse HTTP_USER_AGENT string for the ancient agent
  463.      *
  464.      * @param array $agent parts of the User-Agent string
  465.      * @return mixed void, or a PEAR error object on error
  466.      */
  467.     function _parseJphone(&$agent)
  468.     {
  469.         $count count($agent);
  470.         $this->_is3G = false;
  471.  
  472.         if ($count > 1{
  473.  
  474.             // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
  475.             $this->_packetCompliant = true;
  476.             @list($this->name$this->version$this->_model,
  477.                   $serialNumberexplode('/'$agent[0]);
  478.             if ($serialNumber{
  479.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  480.                     return $this->noMatch();
  481.                 }
  482.                 $this->_serialNumber $matches[1];
  483.             }
  484.             list($this->_vendor$this->_vendorVersion=
  485.                 explode('/'$agent[1]);
  486.             for ($i = 2; $i $count; ++$i{
  487.                 list($key$valueexplode('/'$agent[$i]);
  488.                 $this->_javaInfo[$key$value;
  489.             }
  490.         else {
  491.  
  492.             // J-PHONE/2.0/J-DN02
  493.             @list($this->name$this->version$model=
  494.                 explode('/'$agent[0]);
  495.             $this->_model  = (string)$model;
  496.             if ($this->_model{
  497.                 if (preg_match('!V\d+([A-Z]+)!'$this->_model$matches)) {
  498.                     $this->_vendor $matches[1];
  499.                 elseif (preg_match('!J-([A-Z]+)!'$this->_model$matches)) {
  500.                     $this->_vendor $matches[1];
  501.                 }
  502.             }
  503.         }
  504.     }
  505.  
  506.     // }}}
  507.     // {{{ _parseMotorola()
  508.  
  509.     /**
  510.      * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
  511.      *
  512.      * @param array $agent parts of the User-Agent string
  513.      * @return mixed void, or a PEAR error object on error
  514.      */
  515.     function _parseMotorola(&$agent)
  516.     {
  517.         $count count($agent);
  518.         $this->_packetCompliant = true;
  519.         $this->_vendor 'MOT';
  520.  
  521.         // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  522.         list($name$this->_vendorVersionexplode('/'$agent[0]);
  523.         $this->_model substr(strrchr($name'-')1);
  524.  
  525.         for ($i = 2; $i $count; ++$i{
  526.             list($key$valueexplode('/'$agent[$i]);
  527.             $this->_javaInfo[$key$value;
  528.         }
  529.     }
  530.  
  531.     /**#@-*/
  532. }
  533.  
  534. /*
  535.  * Local Variables:
  536.  * mode: php
  537.  * coding: iso-8859-1
  538.  * tab-width: 4
  539.  * c-basic-offset: 4
  540.  * c-hanging-comment-ender-p: nil
  541.  * indent-tabs-mode: nil
  542.  * End:
  543.  */
  544. ?>

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