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

Source for file JPhone.php

Documentation is available at JPhone.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: JPhone.php,v 1.7 2004/02/08 11:58:38 kuboa Exp $
  20. //
  21.  
  22. require_once(dirname(__FILE__'/Common.php');
  23. require_once(dirname(__FILE__'/Display.php');
  24.  
  25. /**
  26.  * J-PHONE implementation
  27.  *
  28.  * Net_UserAgent_Mobile_JPhone is a subclass of
  29.  * {@link Net_UserAgent_Mobile_Common}, which implements J-PHONE 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.7 $
  62.  * @see      Net_UserAgent_Mobile_Common
  63.  * @link     http://www.dp.j-phone.com/jsky/user.html
  64.  * @link     http://www.dp.j-phone.com/jsky/position.html
  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 $_packet_compliant = false;
  85.  
  86.     /**
  87.      * terminal unique serial number
  88.      * @var string 
  89.      */
  90.     var $_serial_number = 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 $_vendor_version = null;
  103.  
  104.     /**
  105.      * Java profiles
  106.      * @var array 
  107.      */
  108.     var $_java_info = 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.     // {{{ parse()
  131.  
  132.     /**
  133.      * parse HTTP_USER_AGENT string
  134.      *
  135.      * @return mixed void, or a PEAR error object on error
  136.      */
  137.     function parse()
  138.     {
  139.         $agent explode(' '$this->getUserAgent());
  140.         $count count($agent);
  141.  
  142.         if ($count > 1{
  143.  
  144.             // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
  145.             $this->_packet_compliant = true;
  146.             @list($this->name$this->version$this->_model,
  147.                  $serial_numberexplode('/'$agent[0]);
  148.             if ($serial_number{
  149.                 if (!preg_match('/^SN(.+)/'$serial_number,
  150.                                 $matches)
  151.                     {
  152.                     return $this->noMatch();
  153.                 }
  154.                 $this->_serial_number $matches[1];
  155.             }
  156.             list($this->_vendor$this->_vendor_version=
  157.                 explode('/'$agent[1]);
  158.             for ($i = 2; $i $count; ++$i{
  159.                 list($key$valueexplode('/'$agent[$i]);
  160.                 $this->_java_info[$key$value;
  161.             }
  162.         else {
  163.  
  164.             // J-PHONE/2.0/J-DN02
  165.             @list($this->name$this->version$model=
  166.                 explode('/'$agent[0]);
  167.             $this->_model  = (string)$model;
  168.             if ($this->_model{
  169.                 preg_match('/J-([A-Z]+)/'$this->_model$matches);
  170.                 $this->_vendor $matches[1];
  171.             }
  172.         }
  173.     }
  174.  
  175.     // }}}
  176.     // {{{ makeDisplay()
  177.  
  178.     /**
  179.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  180.      *
  181.      * @return object newly created {@link Net_UserAgent_Mobile_Display}
  182.      *      object
  183.      * @see Net_UserAgent_Mobile_Display
  184.      */
  185.     function makeDisplay(
  186.     {
  187.         @list($width$height=
  188.             explode('*'$this->getHeader('x-jphone-display'));
  189.         $color = false;
  190.         $depth = 0;
  191.         if ($color_string $this->getHeader('x-jphone-color')) {
  192.             preg_match('/^([CG])(\d+)$/'$color_string$matches);
  193.             $color $matches[1=== 'C' ? true : false;
  194.             $depth $matches[2];
  195.         }
  196.         return new Net_UserAgent_Mobile_Display(array(
  197.                                                       'width'  => $width,
  198.                                                       'height' => $height,
  199.                                                       'depth'  => $depth,
  200.                                                       'color'  => $color)
  201.                                                 );
  202.     }
  203.  
  204.     // }}}
  205.     // {{{ getModel()
  206.  
  207.     /**
  208.      * returns name of the model like 'J-DN02'
  209.      *
  210.      * @return string 
  211.      */
  212.     function getModel()
  213.     {
  214.         return $this->_model;
  215.     }
  216.  
  217.     // }}}
  218.     // {{{ isPacketCompliant()
  219.  
  220.     /**
  221.      * returns whether the agent is packet connection complicant or not
  222.      *
  223.      * @return boolean 
  224.      */
  225.     function isPacketCompliant()
  226.     {
  227.         return $this->_packet_compliant;
  228.     }
  229.  
  230.     // }}}
  231.     // {{{ getSerialNumber()
  232.  
  233.     /**
  234.      * return terminal unique serial number. returns null if user forbids to
  235.      * send his/her serial number.
  236.      *
  237.      * @return string 
  238.      */
  239.     function getSerialNumber()
  240.     {
  241.         return $this->_serial_number;
  242.     }
  243.  
  244.     // }}}
  245.     // {{{ getVendor()
  246.  
  247.     /**
  248.      * returns vendor code like 'SH'
  249.      *
  250.      * @return string 
  251.      */
  252.     function getVendor()
  253.     {
  254.         return $this->_vendor;
  255.     }
  256.  
  257.     // }}}
  258.     // {{{ getVendorVersion()
  259.  
  260.     /**
  261.      * returns vendor version like '0001a'. returns null if unknown.
  262.      *
  263.      * @return string 
  264.      */
  265.     function getVendorVersion()
  266.     {
  267.         return $this->_vendor_version;
  268.     }
  269.  
  270.     // }}}
  271.     // {{{ getJavaInfo()
  272.  
  273.     /**
  274.      * returns array of Java profiles
  275.      *
  276.      * Array structure is something like:
  277.      *
  278.      * - 'Profile'       => 'MIDP-1.0',
  279.      * - 'Configuration' => 'CLDC-1.0',
  280.      * - 'Ext-Profile'   => 'JSCL-1.1.0'
  281.      *
  282.      * @return array 
  283.      */
  284.     function getJavaInfo()
  285.     {
  286.         return $this->_java_info;
  287.     }
  288.  
  289.     /**#@-*/
  290. }
  291.  
  292. /*
  293.  * Local Variables:
  294.  * mode: php
  295.  * coding: iso-8859-1
  296.  * tab-width: 4
  297.  * c-basic-offset: 4
  298.  * c-hanging-comment-ender-p: nil
  299.  * indent-tabs-mode: nil
  300.  * End:
  301.  */
  302. ?>

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