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.24 2005/08/18 07:18:04 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.24 $
  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|SO213iS)' => '4.0',
  239.                                     'eggy|P751v' => '3.2',
  240.                                     '505i|252i|900i|506i|880i|253i|P213i|901i|700i|851i' => '5.0'
  241.                                     );
  242.         }
  243.  
  244.         foreach ($htmlVersionMap as $key => $value{
  245.             if (preg_match("/$key/"$this->_model)) {
  246.                 return $value;
  247.             }
  248.         }
  249.         return null;
  250.     }
  251.  
  252.     // }}}
  253.     // {{{ getCacheSize()
  254.  
  255.     /**
  256.      * returns cache size as kilobytes unit. returns 5 if unknown.
  257.      *
  258.      * @return integer 
  259.      */
  260.     function getCacheSize()
  261.     {
  262.         if ($this->_cacheSize{
  263.             return $this->_cacheSize;
  264.         }
  265.  
  266.         static $defaultCacheSize;
  267.         if (!isset($defaultCacheSize)) {
  268.             $defaultCacheSize = 5;
  269.         }
  270.         return $defaultCacheSize;
  271.     }
  272.  
  273.     // }}}
  274.     // {{{ getSeries()
  275.  
  276.     /**
  277.      * returns series name like '502i'. returns null if unknown.
  278.      *
  279.      * @return string 
  280.      */
  281.     function getSeries()
  282.     {
  283.         if ($this->isFOMA(&& preg_match('/(\d{4})/'$this->_model)) {
  284.             return 'FOMA';
  285.         }
  286.  
  287.         if (preg_match('/(\d{3}i)/'$this->_model$matches)) {
  288.             return $matches[1];
  289.         }
  290.  
  291.         if ($this->_model == 'P651ps'{
  292.             return '651';
  293.         }
  294.  
  295.         return null;
  296.     }
  297.  
  298.     // }}}
  299.     // {{{ getVendor()
  300.  
  301.     /**
  302.      * returns vender code like 'SO' for Sony. returns null if unknown.
  303.      *
  304.      * @return string 
  305.      */
  306.     function getVendor()
  307.     {
  308.         if (preg_match('/([A-Z]+)\d/'$this->_model$matches)) {
  309.             return $matches[1];
  310.         }
  311.         return null;
  312.     }
  313.  
  314.     // }}}
  315.     // {{{ getModel()
  316.  
  317.     /**
  318.      * returns name of the model like 'P502i'
  319.      *
  320.      * @return string 
  321.      */
  322.     function getModel()
  323.     {
  324.         return $this->_model;
  325.     }
  326.  
  327.     // }}}
  328.     // {{{ getStatus()
  329.  
  330.     /**
  331.      * returns status like "TB", "TC", "TD" or "TJ", which means:
  332.      * 
  333.      * TB | Browsers
  334.      * TC | Browsers with image off (only Available in HTML 5.0)
  335.      * TD | Fetching JAR
  336.      * TJ | i-Appli
  337.      *
  338.      * @return string 
  339.      */
  340.     function getStatus()
  341.     {
  342.         return $this->_status;
  343.     }
  344.  
  345.     // }}}
  346.     // {{{ getBandwidth()
  347.  
  348.     /**
  349.      * returns bandwidth like 32 as killobytes unit. Only vailable in eggy,
  350.      * returns null otherwise.
  351.      *
  352.      * @return integer 
  353.      */
  354.     function getBandwidth()
  355.     {
  356.         return $this->_bandwidth;
  357.     }
  358.  
  359.     // }}}
  360.     // {{{ getSerialNumber()
  361.  
  362.     /**
  363.      * returns hardware unique serial number (15 digit in FOMA, 11 digit
  364.      * otherwise alphanumeric). Only available with form utn attribute.
  365.      * returns null otherwise.
  366.      *
  367.      * @return string 
  368.      */
  369.     function getSerialNumber()
  370.     {
  371.         return $this->_serialNumber;
  372.     }
  373.  
  374.     // }}}
  375.     // {{{ isFOMA()
  376.  
  377.     /**
  378.      * retuns whether it's FOMA or not
  379.      *
  380.      * @return boolean 
  381.      */
  382.     function isFOMA()
  383.     {
  384.         return $this->_isFOMA;
  385.     }
  386.  
  387.     // }}}
  388.     // {{{ getComment()
  389.  
  390.     /**
  391.      * returns comment on user agent string like 'Google Proxy'. returns null
  392.      * otherwise.
  393.      *
  394.      * @return string 
  395.      */
  396.     function getComment()
  397.     {
  398.         return $this->_comment;
  399.     }
  400.  
  401.     // }}}
  402.     // {{{ getCardID()
  403.  
  404.     /**
  405.      * returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA
  406.      * with <form utn> attribute. returns null otherwise.
  407.      *
  408.      * @return string 
  409.      */ 
  410.     function getCardID()
  411.     {
  412.         return $this->_cardID;
  413.     }
  414.  
  415.     // }}}
  416.     // {{{ isGPS()
  417.  
  418.     /**
  419.      * @return boolean 
  420.      */ 
  421.     function isGPS()
  422.     {
  423.         static $gpsModels;
  424.         if (!isset($gpsModels)) {
  425.             $gpsModels = array('F661i''F505iGPS');
  426.         }
  427.         return in_array($this->_model$gpsModels);
  428.     }
  429.  
  430.     // }}}
  431.     // {{{ getCarrierShortName()
  432.  
  433.     /**
  434.      * returns the short name of the carrier
  435.      *
  436.      * @return string 
  437.      */
  438.     function getCarrierShortName()
  439.     {
  440.         return 'I';
  441.     }
  442.  
  443.     // }}}
  444.     // {{{ getCarrierLongName()
  445.  
  446.     /**
  447.      * returns the long name of the carrier
  448.      *
  449.      * @return string 
  450.      */
  451.     function getCarrierLongName()
  452.     {
  453.         return 'DoCoMo';
  454.     }
  455.  
  456.     /**#@-*/
  457.  
  458.     /**#@+
  459.      * @access private
  460.      */
  461.  
  462.     // }}}
  463.     // {{{ _parseMain()
  464.  
  465.     /**
  466.      * parse main part of HTTP_USER_AGENT string (not FOMA)
  467.      *
  468.      * @param string $main main part of HTTP_USER_AGENT string
  469.      * @return mixed void, or a PEAR error object on error
  470.      */ 
  471.     function _parseMain($main)
  472.     {
  473.         @list($this->name$this->version$this->_model$cache$rest=
  474.             explode('/'$main5);
  475.         if ($this->_model === 'SH505i2'{
  476.             $this->_model 'SH505i';
  477.         }
  478.  
  479.         if ($cache{
  480.             if (!preg_match('/^c(\d+)/'$cache$matches)) {
  481.                 return $this->noMatch();
  482.             }
  483.             $this->_cacheSize = (integer)$matches[1];
  484.         }
  485.  
  486.         if ($rest{
  487.             $rest explode('/'$rest);
  488.             foreach ($rest as $value{
  489.                 if (preg_match('/^ser(\w{11})$/'$value$matches)) {
  490.                     $this->_serialNumber $matches[1];
  491.                     continue;
  492.                 }
  493.                 if (preg_match('/^(T[CDBJ])$/'$value$matches)) {
  494.                     $this->_status $matches[1];
  495.                     continue;
  496.                 }
  497.                 if (preg_match('/^s(\d+)$/'$value$matches)) {
  498.                     $this->_bandwidth = (integer)$matches[1];
  499.                     continue;
  500.                 }
  501.                 if (preg_match('/^W(\d+)H(\d+)$/'$value$matches)) {
  502.                     $this->_displayBytes = "{$matches[1]}*{$matches[2]}";
  503.                     continue;
  504.                 }
  505.             }
  506.         }
  507.     }
  508.  
  509.     // }}}
  510.     // {{{ _parseFOMA()
  511.  
  512.     /**
  513.      * parse main part of HTTP_USER_AGENT string (FOMA)
  514.      *
  515.      * @param string $foma main part of HTTP_USER_AGENT string
  516.      * @return mixed void, or a PEAR error object on error
  517.      */ 
  518.     function _parseFOMA($foma)
  519.     {
  520.         if (!preg_match('/^([^(]+)/'$foma$matches)) {
  521.             return $this->noMatch();
  522.         }
  523.         $this->_model $matches[1];
  524.         if ($matches[1=== 'MST_v_SH2101V'{
  525.             $this->_model 'SH2101V';
  526.         }
  527.  
  528.         if (preg_match('/^[^(]+\((.*?)\)$/'$foma$matches)) {
  529.             $rest explode(';'$matches[1]);
  530.             foreach ($rest as $value{
  531.                 if (preg_match('/^c(\d+)/'$value$matches)) {
  532.                     $this->_cacheSize = (integer)$matches[1];
  533.                     continue;
  534.                 }
  535.                 if (preg_match('/^ser(\w{15})$/'$value$matches)) {
  536.                     $this->_serialNumber $matches[1];
  537.                     continue;
  538.                 }
  539.                 if (preg_match('/^(T[CDBJ])$/'$value$matches)) {
  540.                     $this->_status $matches[1];
  541.                     continue;
  542.                 }
  543.                 if (preg_match('/^icc(\w{20})$/'$value$matches)) {
  544.                     $this->_cardID $matches[1];
  545.                     continue;
  546.                 }
  547.                 if (preg_match('/^W(\d+)H(\d+)$/'$value$matches)) {
  548.                     $this->_displayBytes = "{$matches[1]}*{$matches[2]}";
  549.                     continue;
  550.                 }
  551.                 return $this->noMatch();
  552.             }
  553.         }
  554.     }
  555.  
  556.     /**#@-*/
  557. }
  558.  
  559. /*
  560.  * Local Variables:
  561.  * mode: php
  562.  * coding: iso-8859-1
  563.  * tab-width: 4
  564.  * c-basic-offset: 4
  565.  * c-hanging-comment-ender-p: nil
  566.  * indent-tabs-mode: nil
  567.  * End:
  568.  */
  569. ?>

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