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

Source for file SoftBank.php

Documentation is available at SoftBank.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: SoftBank.php,v 1.1 2009/05/26 08:48:16 kuboa Exp $
  37.  * @link       http://creation.mb.softbank.jp/
  38.  * @since      File available since Release 0.20.0
  39.  */
  40.  
  41. require_once 'Net/UserAgent/Mobile/Common.php';
  42. require_once 'Net/UserAgent/Mobile/Display.php';
  43. require_once 'Net/UserAgent/Mobile.php';
  44.  
  45. // {{{ Net_UserAgent_Mobile_SoftBank
  46.  
  47. /**
  48.  * SoftBank implementation
  49.  *
  50.  * Net_UserAgent_Mobile_SoftBank is a subclass of {@link Net_UserAgent_Mobile_Common},
  51.  * which implements SoftBank user agents.
  52.  *
  53.  * SYNOPSIS:
  54.  * <code>
  55.  * require_once 'Net/UserAgent/Mobile.php';
  56.  *
  57.  * $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
  58.  * $agent = &Net_UserAgent_Mobile::factory();
  59.  *
  60.  * printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
  61.  * printf("Version: %s\n", $agent->getVersion()); // 2.0
  62.  * printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
  63.  * if ($agent->isPacketCompliant()) {
  64.  *     print "Packet is compliant.\n"; // false
  65.  * }
  66.  *
  67.  * // only availabe in Java compliant
  68.  * // 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'
  69.  * printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
  70.  * printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
  71.  * printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
  72.  *
  73.  * $info = $agent->getJavaInfo();  // array
  74.  * foreach ($info as $key => $value) {
  75.  *     print "$key: $value\n";
  76.  * }
  77.  * </code>
  78.  *
  79.  * @category   Networking
  80.  * @package    Net_UserAgent_Mobile
  81.  * @author     KUBO Atsuhiro <kubo@iteman.jp>
  82.  * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
  83.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  84.  * @version    Release: 1.0.0
  85.  * @link       http://creation.mb.softbank.jp/
  86.  * @since      Class available since Release 0.20.0
  87.  */
  88. {
  89.  
  90.     // {{{ properties
  91.  
  92.     /**#@+
  93.      * @access public
  94.      */
  95.  
  96.     /**#@-*/
  97.  
  98.     /**#@+
  99.      * @access private
  100.      */
  101.  
  102.     /**
  103.      * whether the agent is packet connection complicant or not
  104.      * @var boolean 
  105.      */
  106.     var $_packetCompliant = false;
  107.  
  108.     /**
  109.      * terminal unique serial number
  110.      * @var string 
  111.      */
  112.     var $_serialNumber;
  113.  
  114.     /**
  115.      * vendor code like 'SH'
  116.      * @var string 
  117.      */
  118.     var $_vendor '';
  119.  
  120.     /**
  121.      * vendor version like '0001a'
  122.      * @var string 
  123.      */
  124.     var $_vendorVersion;
  125.  
  126.     /**
  127.      * Java profiles
  128.      * @var array 
  129.      */
  130.     var $_javaInfo = array();
  131.  
  132.     /**
  133.      * whether the agent is 3G
  134.      * @var boolean 
  135.      */
  136.     var $_is3G = true;
  137.  
  138.     /**
  139.      * the name of the mobile phone
  140.      * @var string 
  141.      */
  142.     var $_msname '';
  143.  
  144.     /**#@-*/
  145.  
  146.     /**#@+
  147.      * @access public
  148.      */
  149.  
  150.     // }}}
  151.     // {{{ isJPhone()
  152.  
  153.     /**
  154.      * returns true
  155.      *
  156.      * @return boolean 
  157.      */
  158.     function isJPhone()
  159.     {
  160.         return $this->isSoftBank();
  161.     }
  162.  
  163.     // }}}
  164.     // {{{ isVodafone()
  165.  
  166.     /**
  167.      * returns true
  168.      *
  169.      * @return boolean 
  170.      */
  171.     function isVodafone()
  172.     {
  173.         return $this->isSoftBank();
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ parse()
  178.  
  179.     /**
  180.      * Parses HTTP_USER_AGENT string.
  181.      *
  182.      * @param string $userAgent User-Agent string
  183.      * @throws Net_UserAgent_Mobile_Error
  184.      */
  185.     function parse($userAgent)
  186.     {
  187.         $agent explode(' '$userAgent);
  188.         preg_match('!^(?:(SoftBank|Semulator|Vodafone|Vemulator|J-PHONE|J-EMULATOR)/\d\.\d|MOT-|MOTEMULATOR)!',
  189.                    $agent[0]$matches
  190.                    );
  191.         if (count($matches> 1{
  192.             $carrier $matches[1];
  193.         else {
  194.             $carrier 'Motorola';
  195.         }
  196.  
  197.         switch ($carrier{
  198.         case 'SoftBank':
  199.         case 'Semulator':
  200.         case 'Vodafone':
  201.         case 'Vemulator':
  202.             $result $this->_parseVodafone($agent);
  203.             break;
  204.         case 'J-PHONE':
  205.         case 'J-EMULATOR':
  206.             $result $this->_parseJphone($agent);
  207.             break;
  208.         case 'Motorola':
  209.         case 'MOTEMULATOR':
  210.             $result $this->_parseMotorola($agent);
  211.             break;
  212.         }
  213.  
  214.         if (Net_UserAgent_Mobile::isError($result)) {
  215.             return $result;
  216.         }
  217.  
  218.         $this->_msname $this->getHeader('X-JPHONE-MSNAME');
  219.     }
  220.  
  221.     // }}}
  222.     // {{{ makeDisplay()
  223.  
  224.     /**
  225.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  226.      *
  227.      * @return Net_UserAgent_Mobile_Display 
  228.      */
  229.     function makeDisplay(
  230.     {
  231.         @list($width$heightexplode('*'$this->getHeader('X-JPHONE-DISPLAY'));
  232.         $color = false;
  233.         $depth = 0;
  234.         if ($color_string $this->getHeader('X-JPHONE-COLOR')) {
  235.             preg_match('!^([CG])(\d+)$!'$color_string$matches);
  236.             $color $matches[1=== 'C' ? true : false;
  237.             $depth $matches[2];
  238.         }
  239.  
  240.         return new Net_UserAgent_Mobile_Display(array('width'  => $width,
  241.                                                       'height' => $height,
  242.                                                       'depth'  => $depth,
  243.                                                       'color'  => $color)
  244.                                                 );
  245.     }
  246.  
  247.     // }}}
  248.     // {{{ isPacketCompliant()
  249.  
  250.     /**
  251.      * returns whether the agent is packet connection complicant or not
  252.      *
  253.      * @return boolean 
  254.      */
  255.     function isPacketCompliant()
  256.     {
  257.         return $this->_packetCompliant;
  258.     }
  259.  
  260.     // }}}
  261.     // {{{ getSerialNumber()
  262.  
  263.     /**
  264.      * return terminal unique serial number. returns null if user forbids to send
  265.      * his/her serial number.
  266.      *
  267.      * @return string 
  268.      */
  269.     function getSerialNumber()
  270.     {
  271.         return $this->_serialNumber;
  272.     }
  273.  
  274.     // }}}
  275.     // {{{ getVendor()
  276.  
  277.     /**
  278.      * returns vendor code like 'SH'
  279.      *
  280.      * @return string 
  281.      */
  282.     function getVendor()
  283.     {
  284.         return $this->_vendor;
  285.     }
  286.  
  287.     // }}}
  288.     // {{{ getVendorVersion()
  289.  
  290.     /**
  291.      * returns vendor version like '0001a'. returns null if unknown.
  292.      *
  293.      * @return string 
  294.      */
  295.     function getVendorVersion()
  296.     {
  297.         return $this->_vendorVersion;
  298.     }
  299.  
  300.     // }}}
  301.     // {{{ getJavaInfo()
  302.  
  303.     /**
  304.      * returns array of Java profiles
  305.      *
  306.      * Array structure is something like:
  307.      *
  308.      * - 'Profile'       => 'MIDP-1.0',
  309.      * - 'Configuration' => 'CLDC-1.0',
  310.      * - 'Ext-Profile'   => 'JSCL-1.1.0'
  311.      *
  312.      * @return array 
  313.      */
  314.     function getJavaInfo()
  315.     {
  316.         return $this->_javaInfo;
  317.     }
  318.  
  319.     // }}}
  320.     // {{{ getCarrierShortName()
  321.  
  322.     /**
  323.      * returns the short name of the carrier
  324.      *
  325.      * @return string 
  326.      */
  327.     function getCarrierShortName()
  328.     {
  329.         return 'S';
  330.     }
  331.  
  332.     // }}}
  333.     // {{{ getCarrierLongName()
  334.  
  335.     /**
  336.      * returns the long name of the carrier
  337.      *
  338.      * @return string 
  339.      */
  340.     function getCarrierLongName()
  341.     {
  342.         return 'SoftBank';
  343.     }
  344.  
  345.     // }}}
  346.     // {{{ isTypeC()
  347.  
  348.     /**
  349.      * returns true if the type is C
  350.      *
  351.      * @return boolean 
  352.      */
  353.     function isTypeC()
  354.     {
  355.         if ($this->_is3G || !preg_match('!^[32]\.!'$this->version)) {
  356.             return false;
  357.         }
  358.  
  359.         return true;
  360.     }
  361.  
  362.     // }}}
  363.     // {{{ isTypeP()
  364.  
  365.     /**
  366.      * returns true if the type is P
  367.      *
  368.      * @return boolean 
  369.      */
  370.     function isTypeP()
  371.     {
  372.         if ($this->_is3G || !preg_match('!^4\.!'$this->version)) {
  373.             return false;
  374.         }
  375.  
  376.         return true;
  377.     }
  378.  
  379.     // }}}
  380.     // {{{ isTypeW()
  381.  
  382.     /**
  383.      * returns true if the type is W
  384.      *
  385.      * @return boolean 
  386.      */
  387.     function isTypeW()
  388.     {
  389.         if ($this->_is3G || !preg_match('!^5\.!'$this->version)) {
  390.             return false;
  391.         }
  392.  
  393.         return true;
  394.     }
  395.  
  396.     // }}}
  397.     // {{{ isType3GC()
  398.  
  399.     /**
  400.      * returns true if the type is 3GC
  401.      *
  402.      * @return boolean 
  403.      */
  404.     function isType3GC()
  405.     {
  406.         return $this->_is3G;
  407.     }
  408.  
  409.     // }}}
  410.     // {{{ getMsname()
  411.  
  412.     /**
  413.      * returns the name of the mobile phone
  414.      *
  415.      * @return string the name of the mobile phone
  416.      */
  417.     function getMsname()
  418.     {
  419.         return $this->_msname;
  420.     }
  421.  
  422.     // }}}
  423.     // {{{ isSoftBank()
  424.  
  425.     /**
  426.      * returns true if the agent is SoftBank.
  427.      *
  428.      * @return boolean 
  429.      */
  430.     function isSoftBank()
  431.     {
  432.         return true;
  433.     }
  434.  
  435.     // }}}
  436.     // {{{ getUID()
  437.  
  438.     /**
  439.      * Gets the UID of a subscriber.
  440.      *
  441.      * @return string 
  442.      * @since Method available since Release 1.0.0RC1
  443.      */
  444.     function getUID()
  445.     {
  446.         if (array_key_exists('HTTP_X_JPHONE_UID'$_SERVER)) {
  447.             return $_SERVER['HTTP_X_JPHONE_UID'];
  448.         }
  449.     }
  450.  
  451.     /**#@-*/
  452.  
  453.     /**#@+
  454.      * @access private
  455.      */
  456.  
  457.     // }}}
  458.     // {{{ _parseVodafone()
  459.  
  460.     /**
  461.      * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
  462.      *
  463.      * @param array $agent parts of the User-Agent string
  464.      * @throws Net_UserAgent_Mobile_Error
  465.      */
  466.     function _parseVodafone($agent)
  467.     {
  468.         $this->_packetCompliant = true;
  469.  
  470.         // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  471.         // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
  472.         // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  473.         @list($this->name$this->version$this->_rawModel$modelVersion,
  474.               $serialNumberexplode('/'$agent[0]);
  475.         if ($serialNumber{
  476.             if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  477.                 return $this->noMatch();
  478.             }
  479.  
  480.             $this->_serialNumber $matches[1];
  481.         }
  482.  
  483.         if (!preg_match('!^([a-z]+)((?:[a-z]|\d){4})$!i'$modelVersion$matches)) {
  484.             return $this->noMatch();
  485.         }
  486.  
  487.         $this->_vendor $matches[1];
  488.         $this->_vendorVersion $matches[2];
  489.  
  490.         for ($i = 2$count count($agent)$i $count; ++$i{
  491.             @list($key$valueexplode('/'$agent[$i]);
  492.             $this->_javaInfo[$key$value;
  493.         }
  494.     }
  495.  
  496.     // }}}
  497.     // {{{ _parseJphone()
  498.  
  499.     /**
  500.      * parse HTTP_USER_AGENT string for the ancient agent
  501.      *
  502.      * @param array $agent parts of the User-Agent string
  503.      * @throws Net_UserAgent_Mobile_Error
  504.      */
  505.     function _parseJphone($agent)
  506.     {
  507.         $count count($agent);
  508.         $this->_is3G = false;
  509.  
  510.         if ($count > 1{
  511.  
  512.             // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
  513.             $this->_packetCompliant = true;
  514.             @list($this->name$this->version$this->_rawModel$serialNumber=
  515.                 explode('/'$agent[0]);
  516.             if ($serialNumber{
  517.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  518.                     return $this->noMatch();
  519.                 }
  520.  
  521.                 $this->_serialNumber $matches[1];
  522.             }
  523.  
  524.             @list($this->_vendor$this->_vendorVersionexplode('/'$agent[1]);
  525.             for ($i = 2; $i $count; ++$i{
  526.                 @list($key$valueexplode('/'$agent[$i]);
  527.                 $this->_javaInfo[$key$value;
  528.             }
  529.         else {
  530.  
  531.             // J-PHONE/2.0/J-DN02
  532.             @list($this->name$this->version$this->_rawModel$serialNumber=
  533.                 explode('/'$agent[0]);
  534.             if ($serialNumber{
  535.                 if (!preg_match('!^SN(.+)!'$serialNumber$matches)) {
  536.                     return $this->noMatch();
  537.                 }
  538.  
  539.                 $this->_serialNumber $matches[1];
  540.             }
  541.  
  542.             if ($this->_rawModel{
  543.                 if (preg_match('!V\d+([A-Z]+)!'$this->_rawModel$matches)) {
  544.                     $this->_vendor $matches[1];
  545.                 elseif (preg_match('!J-([A-Z]+)!'$this->_rawModel$matches)) {
  546.                     $this->_vendor $matches[1];
  547.                 }
  548.             }
  549.         }
  550.     }
  551.  
  552.     // }}}
  553.     // {{{ _parseMotorola()
  554.  
  555.     /**
  556.      * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
  557.      *
  558.      * @param array $agent parts of the User-Agent string
  559.      */
  560.     function _parseMotorola($agent)
  561.     {
  562.         $this->_packetCompliant = true;
  563.         $this->_vendor 'MOT';
  564.  
  565.         // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
  566.         @list($this->_rawModel$this->_vendorVersionexplode('/'$agent[0]);
  567.         $this->_model substr(strrchr($this->_rawModel'-')1);
  568.  
  569.         for ($i = 2$count count($agent)$i $count; ++$i{
  570.             @list($key$valueexplode('/'$agent[$i]);
  571.             $this->_javaInfo[$key$value;
  572.         }
  573.     }
  574.  
  575.     /**#@-*/
  576.  
  577.     // }}}
  578. }
  579.  
  580. // }}}
  581.  
  582. /*
  583.  * Local Variables:
  584.  * mode: php
  585.  * coding: iso-8859-1
  586.  * tab-width: 4
  587.  * c-basic-offset: 4
  588.  * c-hanging-comment-ender-p: nil
  589.  * indent-tabs-mode: nil
  590.  * End:
  591.  */

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