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.1 2004/09/25 12:17:42 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.1 $
  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.  
  112.     /**#@+
  113.      * @access public
  114.      */
  115.  
  116.     // }}}
  117.     // {{{ isJPhone()
  118.  
  119.     /**
  120.      * returns true
  121.      *
  122.      * @return boolean 
  123.      */
  124.     function isJPhone()
  125.     {
  126.         return true;
  127.     }
  128.  
  129.     // }}}
  130.     // {{{ isVodafone()
  131.  
  132.     /**
  133.      * returns true
  134.      *
  135.      * @return boolean 
  136.      */
  137.     function isVodafone()
  138.     {
  139.         return true;
  140.     }
  141.  
  142.     // }}}
  143.     // {{{ parse()
  144.  
  145.     /**
  146.      * parse HTTP_USER_AGENT string
  147.      *
  148.      * @return mixed void, or a PEAR error object on error
  149.      */
  150.     function parse()
  151.     {
  152.         $agent explode(' '$this->getUserAgent());
  153.         $count count($agent);
  154.  
  155.         if ($count > 1{
  156.  
  157.             // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
  158.             $this->_packetCompliant = true;
  159.             @list($this->name$this->version$this->_model,
  160.                  $serialNumberexplode('/'$agent[0]);
  161.             if ($serialNumber{
  162.                 if (!preg_match('/^SN(.+)/'$serialNumber,
  163.                                 $matches)
  164.                     {
  165.                     return $this->noMatch();
  166.                 }
  167.                 $this->_serialNumber $matches[1];
  168.             }
  169.             list($this->_vendor$this->_vendorVersion=
  170.                 explode('/'$agent[1]);
  171.             for ($i = 2; $i $count; ++$i{
  172.                 list($key$valueexplode('/'$agent[$i]);
  173.                 $this->_javaInfo[$key$value;
  174.             }
  175.         else {
  176.  
  177.             // J-PHONE/2.0/J-DN02
  178.             @list($this->name$this->version$model=
  179.                 explode('/'$agent[0]);
  180.             $this->_model  = (string)$model;
  181.             if ($this->_model{
  182.                 preg_match('/J-([A-Z]+)/'$this->_model$matches);
  183.                 $this->_vendor $matches[1];
  184.             }
  185.         }
  186.     }
  187.  
  188.     // }}}
  189.     // {{{ makeDisplay()
  190.  
  191.     /**
  192.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  193.      *
  194.      * @return object newly created {@link Net_UserAgent_Mobile_Display}
  195.      *      object
  196.      * @see Net_UserAgent_Mobile_Display
  197.      */
  198.     function makeDisplay(
  199.     {
  200.         @list($width$height=
  201.             explode('*'$this->getHeader('x-jphone-display'));
  202.         $color = false;
  203.         $depth = 0;
  204.         if ($color_string $this->getHeader('x-jphone-color')) {
  205.             preg_match('/^([CG])(\d+)$/'$color_string$matches);
  206.             $color $matches[1=== 'C' ? true : false;
  207.             $depth $matches[2];
  208.         }
  209.         return new Net_UserAgent_Mobile_Display(array(
  210.                                                       'width'  => $width,
  211.                                                       'height' => $height,
  212.                                                       'depth'  => $depth,
  213.                                                       'color'  => $color)
  214.                                                 );
  215.     }
  216.  
  217.     // }}}
  218.     // {{{ getModel()
  219.  
  220.     /**
  221.      * returns name of the model like 'J-DN02'
  222.      *
  223.      * @return string 
  224.      */
  225.     function getModel()
  226.     {
  227.         return $this->_model;
  228.     }
  229.  
  230.     // }}}
  231.     // {{{ isPacketCompliant()
  232.  
  233.     /**
  234.      * returns whether the agent is packet connection complicant or not
  235.      *
  236.      * @return boolean 
  237.      */
  238.     function isPacketCompliant()
  239.     {
  240.         return $this->_packetCompliant;
  241.     }
  242.  
  243.     // }}}
  244.     // {{{ getSerialNumber()
  245.  
  246.     /**
  247.      * return terminal unique serial number. returns null if user forbids to
  248.      * send his/her serial number.
  249.      *
  250.      * @return string 
  251.      */
  252.     function getSerialNumber()
  253.     {
  254.         return $this->_serialNumber;
  255.     }
  256.  
  257.     // }}}
  258.     // {{{ getVendor()
  259.  
  260.     /**
  261.      * returns vendor code like 'SH'
  262.      *
  263.      * @return string 
  264.      */
  265.     function getVendor()
  266.     {
  267.         return $this->_vendor;
  268.     }
  269.  
  270.     // }}}
  271.     // {{{ getVendorVersion()
  272.  
  273.     /**
  274.      * returns vendor version like '0001a'. returns null if unknown.
  275.      *
  276.      * @return string 
  277.      */
  278.     function getVendorVersion()
  279.     {
  280.         return $this->_vendorVersion;
  281.     }
  282.  
  283.     // }}}
  284.     // {{{ getJavaInfo()
  285.  
  286.     /**
  287.      * returns array of Java profiles
  288.      *
  289.      * Array structure is something like:
  290.      *
  291.      * - 'Profile'       => 'MIDP-1.0',
  292.      * - 'Configuration' => 'CLDC-1.0',
  293.      * - 'Ext-Profile'   => 'JSCL-1.1.0'
  294.      *
  295.      * @return array 
  296.      */
  297.     function getJavaInfo()
  298.     {
  299.         return $this->_javaInfo;
  300.     }
  301.  
  302.     // }}}
  303.     // {{{ getCarrierShortName()
  304.  
  305.     /**
  306.      * returns the short name of the carrier
  307.      *
  308.      * @return string 
  309.      */
  310.     function getCarrierShortName()
  311.     {
  312.         return 'V';
  313.     }
  314.  
  315.     // }}}
  316.     // {{{ getCarrierLongName()
  317.  
  318.     /**
  319.      * returns the long name of the carrier
  320.      *
  321.      * @return string 
  322.      */
  323.     function getCarrierLongName()
  324.     {
  325.         return 'Vodafone';
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ isTypeC()
  330.  
  331.     /**
  332.      * returns true if the type is C
  333.      *
  334.      * @return boolean 
  335.      */
  336.     function isTypeC()
  337.     {
  338.         if (preg_match('/^3\./'$this->version)) {
  339.             return true;
  340.         }
  341.  
  342.         if (preg_match('/^2\./'$this->version)) {
  343.             return true;
  344.         }
  345.  
  346.         return false;
  347.     }
  348.  
  349.     // }}}
  350.     // {{{ isTypeP()
  351.  
  352.     /**
  353.      * returns true if the type is P
  354.      *
  355.      * @return boolean 
  356.      */
  357.     function isTypeP()
  358.     {
  359.         if (preg_match('/^4\./'$this->version)) {
  360.             return true;
  361.         }
  362.  
  363.         return false;
  364.     }
  365.  
  366.     // }}}
  367.     // {{{ isTypeW()
  368.  
  369.     /**
  370.      * returns true if the type is W
  371.      *
  372.      * @return boolean 
  373.      */
  374.     function isTypeW()
  375.     {
  376.         if (preg_match('/^5\./'$this->version)) {
  377.             return true;
  378.         }
  379.  
  380.         return false;
  381.     }
  382.  
  383.     /**#@-*/
  384. }
  385.  
  386. /*
  387.  * Local Variables:
  388.  * mode: php
  389.  * coding: iso-8859-1
  390.  * tab-width: 4
  391.  * c-basic-offset: 4
  392.  * c-hanging-comment-ender-p: nil
  393.  * indent-tabs-mode: nil
  394.  * End:
  395.  */
  396. ?>

Documentation generated on Mon, 11 Mar 2019 13:55:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.