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

Source for file DoCoMo.php

Documentation is available at DoCoMo.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: DoCoMo.php,v 1.18 2004/05/27 07:27:55 kuboa Exp $
  20. //
  21.  
  22. require_once(dirname(__FILE__'/Common.php');
  23. require_once(dirname(__FILE__'/Display.php');
  24. require_once(dirname(__FILE__'/DoCoMoDisplayMap.php');
  25.  
  26. /**
  27.  * NTT DoCoMo implementation
  28.  *
  29.  * Net_UserAgent_Mobile_DoCoMo is a subclass of
  30.  * {@link Net_UserAgent_Mobile_Common}, which implements NTT docomo i-mode
  31.  * user agents.
  32.  *
  33.  * SYNOPSIS:
  34.  * <code>
  35.  * require_once('Net/UserAgent/Mobile.php');
  36.  *
  37.  * $_SERVER['HTTP_USER_AGENT'] = 'DoCoMo/1.0/P502i/c10';
  38.  * $agent = &Net_UserAgent_Mobile::factory();
  39.  *
  40.  * printf("Name: %s\n", $agent->getName()); // 'DoCoMo'
  41.  * printf("Version: %s\n", $agent->getVersion()); // 1.0
  42.  * printf("HTML version: %s\n", $agent->getHTMLVersion()); // 2.0
  43.  * printf("Model: %s\n", $agent->getModel()); // 'P502i'
  44.  * printf("Cache: %dk\n", $agent->getCacheSize()); // 10
  45.  * if ($agent->isFOMA()) {
  46.  *     print "FOMA\n";             // false
  47.  * }
  48.  * printf("Vendor: %s\n", $agent->getVendor()); // 'P'
  49.  * printf("Series: %s\n", $agent->getSeries()); // '502i'
  50.  *
  51.  * // only available with <form utn>
  52.  * // e.g.) 'DoCoMo/1.0/P503i/c10/serNMABH200331';
  53.  * printf("Serial: %s\n", $agent->getSerialNumber()); // 'NMABH200331'
  54.  *
  55.  * // e.g.) 'DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)';
  56.  * printf("Serial: %s\n", $agent->getSerialNumber()); // '0123456789abcde'
  57.  * printf("Card ID: %s\n", $agent->getCardID()); // '01234567890123456789'
  58.  *
  59.  * // e.g.) 'DoCoMo/1.0/P502i (Google CHTML Proxy/1.0)'
  60.  * printf("Comment: %s\n", $agent->getComment()); // 'Google CHTML Proxy/1.0'
  61.  *
  62.  * // only available in eggy/M-stage
  63.  * // e.g.) 'DoCoMo/1.0/eggy/c300/s32/kPHS-K'
  64.  * printf("Bandwidth: %dkbps\n", $agent->getBandwidth()); // 32
  65.  * </code>
  66.  *
  67.  * @package  Net_UserAgent_Mobile
  68.  * @category Networking
  69.  * @author   KUBO Atsuhiro <kubo@isite.co.jp>
  70.  * @access   public
  71.  * @version  $Revision: 1.18 $
  72.  * @see      Net_UserAgent_Mobile_Common
  73.  * @link     http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html
  74.  * @link     http://www.nttdocomo.co.jp/p_s/imode/tag/imodetag.html
  75.  * @link     http://www.nttdocomo.co.jp/p_s/imode/tag/utn.html
  76.  * @link     http://www.nttdocomo.co.jp/p_s/mstage/visual/contents/cnt_mpage.html
  77.  */
  78. {
  79.  
  80.     // {{{ properties
  81.  
  82.     /**#@+
  83.      * @access private
  84.      */
  85.  
  86.     /**
  87.      * name of the model like 'P502i'
  88.      * @var string 
  89.      */
  90.     var $_model '';
  91.  
  92.     /**
  93.      * status of the cache (TC, TB, TD, TJ)
  94.      * @var string 
  95.      */
  96.     var $_status '';
  97.  
  98.     /**
  99.      * bandwidth like 32 as kilobytes unit
  100.      * @var integer 
  101.      */
  102.     var $_bandwidth = null;
  103.  
  104.     /**
  105.      * hardware unique serial number
  106.      * @var string 
  107.      */
  108.     var $_serialNumber = null;
  109.  
  110.     /**
  111.      * whether it's FOMA or not
  112.      * @var boolean 
  113.      */
  114.     var $_isFOMA = false;
  115.  
  116.     /**
  117.      * FOMA Card ID (20 digit alphanumeric)
  118.      * @var string 
  119.      */
  120.     var $_cardID = null;
  121.  
  122.     /**
  123.      * comment on user agent string like 'Google Proxy'
  124.      * @var string 
  125.      */
  126.     var $_comment = null;
  127.  
  128.     /**
  129.      * cache size as killobytes unit
  130.      * @var integer 
  131.      */
  132.     var $_cacheSize;
  133.  
  134.     /**
  135.      * width and height of the display
  136.      * @var string 
  137.      */
  138.     var $_displayBytes '';
  139.  
  140.     /**#@-*/
  141.  
  142.     /**#@+
  143.      * @access public
  144.      */
  145.  
  146.     // }}}
  147.     // {{{ isDoCoMo()
  148.  
  149.     /**
  150.      * returns true
  151.      *
  152.      * @return boolean 
  153.      */
  154.     function isDoCoMo()
  155.     {
  156.         return true;
  157.     }
  158.  
  159.     // }}}
  160.     // {{{ parse()
  161.  
  162.     /**
  163.      * parse HTTP_USER_AGENT string
  164.      *
  165.      * @return mixed void, or a PEAR error object on error
  166.      */
  167.     function parse()
  168.     {
  169.         @list($main$foma_or_comment=
  170.             explode(' '$this->getUserAgent()2);
  171.  
  172.         if ($foma_or_comment
  173.             && preg_match('/^\((.*)\)$/'$foma_or_comment$matches)
  174.             {
  175.  
  176.             // DoCoMo/1.0/P209is (Google CHTML Proxy/1.0)
  177.             $this->_comment $matches[1];
  178.             $result $this->_parseMain($main);
  179.         elseif ($foma_or_comment{
  180.  
  181.             // DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)
  182.             $this->_isFOMA = true;
  183.             list($this->name$this->versionexplode('/'$main);
  184.             $result $this->_parseFOMA($foma_or_comment);
  185.         else {
  186.  
  187.             // DoCoMo/1.0/R692i/c10
  188.             $result $this->_parseMain($main);
  189.         }
  190.  
  191.         if (Net_UserAgent_Mobile::isError($result)) {
  192.             return $result;
  193.         }
  194.     }
  195.  
  196.     // }}}
  197.     // {{{ makeDisplay()
  198.  
  199.     /**
  200.      * create a new {@link Net_UserAgent_Mobile_Display} class instance
  201.      *
  202.      * @return object newly created {@link Net_UserAgent_Mobile_Display}
  203.      *      object
  204.      * @see Net_UserAgent_Mobile_Display
  205.      * @see Net_UserAgent_Mobile_DoCoMoDisplayMap::get()
  206.      */
  207.     function makeDisplay()
  208.     {
  209.         $display Net_UserAgent_Mobile_DoCoMoDisplayMap::get($this->_model);
  210.         if ($this->_displayBytes !== ''{
  211.             list($widthBytes$heightBytes=
  212.                 explode('*'$this->_displayBytes);
  213.             $display['width_bytes']  $widthBytes;
  214.             $display['height_bytes'$heightBytes;
  215.         }
  216.         return new Net_UserAgent_Mobile_Display($display);
  217.     }
  218.  
  219.     // }}}
  220.     // {{{ getHTMLVersion()
  221.  
  222.     /**
  223.      * returns supported HTML version like '3.0'. retuns null if unknown.
  224.      *
  225.      * @return string 
  226.      */
  227.     function getHTMLVersion()
  228.     {
  229.         static $htmlVersionMap;
  230.         if (!isset($htmlVersionMap)) {
  231.             $htmlVersionMap = array(
  232.                                     '[DFNP]501i' => '1.0',
  233.                                     '502i|821i|209i|691i|(F|N|P|KO)210i|^F671i$' => '2.0',
  234.                                     '(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V' => '3.0',
  235.                                     '504i|251i|^F671iS$|212i|2051|2102V|^F661i$|2701|^F672i$' => '4.0',
  236.                                     'eggy|P751v' => '3.2',
  237.                                     '505i|252i|900i|506i' => '5.0'
  238.                                     );
  239.         }
  240.  
  241.         foreach ($htmlVersionMap as $key => $value{
  242.             if (preg_match("/$key/"$this->_model)) {
  243.                 return $value;
  244.             }
  245.         }
  246.         return null;
  247.     }
  248.  
  249.     // }}}
  250.     // {{{ getCacheSize()
  251.  
  252.     /**
  253.      * returns cache size as kilobytes unit. returns 5 if unknown.
  254.      *
  255.      * @return integer 
  256.      */
  257.     function getCacheSize()
  258.     {
  259.         if ($this->_cacheSize{
  260.             return $this->_cacheSize;
  261.         }
  262.  
  263.         static $defaultCacheSize;
  264.         if (!isset($defaultCacheSize)) {
  265.             $defaultCacheSize = 5;
  266.         }
  267.         return $defaultCacheSize;
  268.     }
  269.  
  270.     // }}}
  271.     // {{{ getSeries()
  272.  
  273.     /**
  274.      * returns series name like '502i'. returns null if unknown.
  275.      *
  276.      * @return string 
  277.      */
  278.     function getSeries()
  279.     {
  280.         if ($this->isFOMA()) {
  281.             return 'FOMA';
  282.         }
  283.         if (preg_match('/(\d{3}i)/'$this->_model$matches)) {
  284.             return $matches[1];
  285.         }
  286.         return null;
  287.     }
  288.  
  289.     // }}}
  290.     // {{{ getVendor()
  291.  
  292.     /**
  293.      * returns vender code like 'SO' for Sony. returns null if unknown.
  294.      *
  295.      * @return string 
  296.      */
  297.     function getVendor()
  298.     {
  299.         if (preg_match('/([A-Z]+)\d/'$this->_model$matches)) {
  300.             return $matches[1];
  301.         }
  302.         return null;
  303.     }
  304.  
  305.     // }}}
  306.     // {{{ getModel()
  307.  
  308.     /**
  309.      * returns name of the model like 'P502i'
  310.      *
  311.      * @return string 
  312.      */
  313.     function getModel()
  314.     {
  315.         return $this->_model;
  316.     }
  317.  
  318.     // }}}
  319.     // {{{ getStatus()
  320.  
  321.     /**
  322.      * returns status of the cache (TB, TD, TJ)
  323.      *
  324.      * @return string 
  325.      */
  326.     function getStatus()
  327.     {
  328.         return $this->_status;
  329.     }
  330.  
  331.     // }}}
  332.     // {{{ getBandwidth()
  333.  
  334.     /**
  335.      * returns bandwidth like 32 as killobytes unit. Only vailable in eggy,
  336.      * returns null otherwise.
  337.      *
  338.      * @return integer 
  339.      */
  340.     function getBandwidth()
  341.     {
  342.         return $this->_bandwidth;
  343.     }
  344.  
  345.     // }}}
  346.     // {{{ getSerialNumber()
  347.  
  348.     /**
  349.      * returns hardware unique serial number (15 digit in FOMA, 11 digit
  350.      * otherwise alphanumeric). Only available with form utn attribute.
  351.      * returns null otherwise.
  352.      *
  353.      * @return string 
  354.      */
  355.     function getSerialNumber()
  356.     {
  357.         return $this->_serialNumber;
  358.     }
  359.  
  360.     // }}}
  361.     // {{{ isFOMA()
  362.  
  363.     /**
  364.      * retuns whether it's FOMA or not
  365.      *
  366.      * @return boolean 
  367.      */
  368.     function isFOMA()
  369.     {
  370.         return $this->_isFOMA;
  371.     }
  372.  
  373.     // }}}
  374.     // {{{ getComment()
  375.  
  376.     /**
  377.      * returns comment on user agent string like 'Google Proxy'. returns null
  378.      * otherwise.
  379.      *
  380.      * @return string 
  381.      */
  382.     function getComment()
  383.     {
  384.         return $this->_comment;
  385.     }
  386.  
  387.     // }}}
  388.     // {{{ getCardID()
  389.  
  390.     /**
  391.      * returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA
  392.      * with <form utn> attribute. returns null otherwise.
  393.      *
  394.      * @return string 
  395.      */ 
  396.     function getCardID()
  397.     {
  398.         return $this->_cardID;
  399.     }
  400.  
  401.     // }}}
  402.     // {{{ isGPS()
  403.  
  404.     /**
  405.      * @return boolean 
  406.      */ 
  407.     function isGPS()
  408.     {
  409.         static $gpsModels;
  410.         if (!isset($gpsModels)) {
  411.             $gpsModels = array('F661i');
  412.         }
  413.         return in_array($this->_model$gpsModels);
  414.     }
  415.  
  416.     /**#@-*/
  417.  
  418.     /**#@+
  419.      * @access private
  420.      */
  421.  
  422.     // }}}
  423.     // {{{ _parseMain()
  424.  
  425.     /**
  426.      * parse main part of HTTP_USER_AGENT string (not FOMA)
  427.      *
  428.      * @param string $main main part of HTTP_USER_AGENT string
  429.      * @return mixed void, or a PEAR error object on error
  430.      */ 
  431.     function _parseMain($main)
  432.     {
  433.         @list($this->name$this->version$this->_model$cache$rest=
  434.             explode('/'$main5);
  435.         if ($this->_model === 'SH505i2'{
  436.             $this->_model 'SH505i';
  437.         }
  438.  
  439.         if ($cache{
  440.             if (!preg_match('/^c(\d+)/'$cache$matches)) {
  441.                 return $this->noMatch();
  442.             }
  443.             $this->_cacheSize = (integer)$matches[1];
  444.         }
  445.  
  446.         if ($rest{
  447.             $rest explode('/'$rest);
  448.             foreach ($rest as $value{
  449.                 if (preg_match('/^ser(\w{11})$/'$value$matches)) {
  450.                     $this->_serialNumber $matches[1];
  451.                     continue;
  452.                 }
  453.                 if (preg_match('/^(T[CDBJ])$/'$value$matches)) {
  454.                     $this->_status $matches[1];
  455.                     continue;
  456.                 }
  457.                 if (preg_match('/^s(\d+)$/'$value$matches)) {
  458.                     $this->_bandwidth = (integer)$matches[1];
  459.                     continue;
  460.                 }
  461.                 if (preg_match('/^W(\d+)H(\d+)$/'$value$matches)) {
  462.                     $this->_displayBytes = "{$matches[1]}*{$matches[2]}";
  463.                     continue;
  464.                 }
  465.             }
  466.         }
  467.     }
  468.  
  469.     // }}}
  470.     // {{{ _parseFOMA()
  471.  
  472.     /**
  473.      * parse main part of HTTP_USER_AGENT string (FOMA)
  474.      *
  475.      * @param string $foma main part of HTTP_USER_AGENT string
  476.      * @return mixed void, or a PEAR error object on error
  477.      */ 
  478.     function _parseFOMA($foma)
  479.     {
  480.         if (!preg_match('/^([^(]+)/'$foma$matches)) {
  481.             return $this->noMatch();
  482.         }
  483.         $this->_model $matches[1];
  484.         if ($matches[1=== 'MST_v_SH2101V'{
  485.             $this->_model 'SH2101V';
  486.         }
  487.  
  488.         if (preg_match('/^[^(]+\((.*?)\)$/'$foma$matches)) {
  489.             $rest explode(';'$matches[1]);
  490.             foreach ($rest as $value{
  491.                 if (preg_match('/^c(\d+)/'$value$matches)) {
  492.                     $this->_cacheSize = (integer)$matches[1];
  493.                     continue;
  494.                 }
  495.                 if (preg_match('/^ser(\w{15})$/'$value$matches)) {
  496.                     $this->_serialNumber $matches[1];
  497.                     continue;
  498.                 }
  499.                 if (preg_match('/^(T[CDBJ])$/'$value$matches)) {
  500.                     $this->_status $matches[1];
  501.                     continue;
  502.                 }
  503.                 if (preg_match('/^icc(\w{20})$/'$value$matches)) {
  504.                     $this->_cardID $matches[1];
  505.                     continue;
  506.                 }
  507.                 if (preg_match('/^W(\d+)H(\d+)$/'$value$matches)) {
  508.                     $this->_displayBytes = "{$matches[1]}*{$matches[2]}";
  509.                     continue;
  510.                 }
  511.                 return $this->noMatch();
  512.             }
  513.         }
  514.     }
  515.  
  516.     /**#@-*/
  517. }
  518.  
  519. /*
  520.  * Local Variables:
  521.  * mode: php
  522.  * coding: iso-8859-1
  523.  * tab-width: 4
  524.  * c-basic-offset: 4
  525.  * c-hanging-comment-ender-p: nil
  526.  * indent-tabs-mode: nil
  527.  * End:
  528.  */
  529. ?>

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