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

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