Source for file DoCoMo.php
Documentation is available at DoCoMo.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>,
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @package Net_UserAgent_Mobile
* @author KUBO Atsuhiro <kubo@iteman.jp>
* @copyright 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: DoCoMo.php,v 1.2 2009/06/23 08:06:58 kuboa Exp $
* @link http://www.nttdocomo.co.jp/service/imode/make/content/spec/useragent/index.html
* @link http://www.nttdocomo.co.jp/service/imode/make/content/browser/browser2/useragent/index.html
* @since File available since Release 0.1
require_once 'Net/UserAgent/Mobile/Common.php';
require_once 'Net/UserAgent/Mobile/Display.php';
require_once 'Net/UserAgent/Mobile.php';
// {{{ Net_UserAgent_Mobile_DoCoMo
* NTT DoCoMo implementation
* Net_UserAgent_Mobile_DoCoMo is a subclass of {@link Net_UserAgent_Mobile_Common},
* which implements NTT docomo i-mode user agents.
* require_once 'Net/UserAgent/Mobile.php';
* $_SERVER['HTTP_USER_AGENT'] = 'DoCoMo/1.0/P502i/c10';
* $agent = &Net_UserAgent_Mobile::factory();
* printf("Name: %s\n", $agent->getName()); // 'DoCoMo'
* printf("Version: %s\n", $agent->getVersion()); // 1.0
* printf("HTML version: %s\n", $agent->getHTMLVersion()); // 2.0
* printf("Model: %s\n", $agent->getModel()); // 'P502i'
* printf("Cache: %dk\n", $agent->getCacheSize()); // 10
* if ($agent->isFOMA()) {
* print "FOMA\n"; // false
* printf("Vendor: %s\n", $agent->getVendor()); // 'P'
* printf("Series: %s\n", $agent->getSeries()); // '502i'
* // only available with <form utn>
* // e.g.) 'DoCoMo/1.0/P503i/c10/serNMABH200331';
* printf("Serial: %s\n", $agent->getSerialNumber()); // 'NMABH200331'
* // e.g.) 'DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)';
* printf("Serial: %s\n", $agent->getSerialNumber()); // '0123456789abcde'
* printf("Card ID: %s\n", $agent->getCardID()); // '01234567890123456789'
* // e.g.) 'DoCoMo/1.0/P502i (Google CHTML Proxy/1.0)'
* printf("Comment: %s\n", $agent->getComment()); // 'Google CHTML Proxy/1.0'
* // e.g.) 'DoCoMo/1.0/D505i/c20/TB/W20H10'
* printf("Status: %s\n", $agent->getStatus()); // 'TB'
* // only available in eggy/M-stage
* // e.g.) 'DoCoMo/1.0/eggy/c300/s32/kPHS-K'
* printf("Bandwidth: %dkbps\n", $agent->getBandwidth()); // 32
* @package Net_UserAgent_Mobile
* @author KUBO Atsuhiro <kubo@iteman.jp>
* @copyright 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.0.0
* @link http://www.nttdocomo.co.jp/service/imode/make/content/spec/useragent/index.html
* @link http://www.nttdocomo.co.jp/service/imode/make/content/browser/browser2/useragent/index.html
* @since Class available since Release 0.1
* status of the cache (TC, TB, TD, TJ)
* bandwidth like 32 as kilobytes unit
* hardware unique serial number
* whether it's FOMA or not
* FOMA Card ID (20 digit alphanumeric)
* comment on user agent string like 'Google Proxy'
* cache size as killobytes unit
* width and height of the display
* The model names which have GPS capability.
* @since Property available since Release 1.0.0RC1
var $_gpsModels = array ('F884i',
* The HTML versions which maps models to HTML versions.
* @since Property available since Release 1.0.0RC1
var $_htmlVersions = array (
* Parses HTTP_USER_AGENT string.
* @param string $userAgent User-Agent string
* @throws Net_UserAgent_Mobile_Error
function parse($userAgent)
@list ($main, $foma_or_comment) = explode(' ', $userAgent, 2 );
&& preg_match('/^\((.*)\)$/', $foma_or_comment, $matches)
// DoCoMo/1.0/P209is (Google CHTML Proxy/1.0)
$this->_comment = $matches[1 ];
$result = $this->_parseMain ($main);
} elseif ($foma_or_comment) {
// DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)
$result = $this->_parseFOMA ($foma_or_comment);
$result = $this->_parseMain ($main);
* create a new {@link Net_UserAgent_Mobile_Display} class instance
* @return Net_UserAgent_Mobile_Display
include_once 'Net/UserAgent/Mobile/DoCoMo/ScreenInfo.php';
$display = $screenInfo->get ($this->getModel());
if (!is_null($this->_displayBytes)) {
@list ($widthBytes, $heightBytes) = explode('*', $this->_displayBytes);
$display['width_bytes'] = $widthBytes;
$display['height_bytes'] = $heightBytes;
* Gets the HTML version like '3.0'. Returns null if unknown.
return @$this->_htmlVersions[ $this->getModel() ];
* returns cache size as kilobytes unit. returns 5 if unknown.
return $this->_cacheSize;
* returns series name like '502i'. returns null if unknown.
if (preg_match('/(\d{3}i)/', $this->_rawModel, $matches)) {
if ($this->_rawModel == 'P651ps') {
* returns vender code like 'SO' for Sony. returns null if unknown.
if (preg_match('/([A-Z]+)\d/', $this->_rawModel, $matches)) {
* returns status like "TB", "TC", "TD" or "TJ", which means:
* TC | Browsers with image off (only Available in HTML 5.0)
* returns bandwidth like 32 as killobytes unit. Only vailable in eggy,
* returns null otherwise.
return $this->_bandwidth;
* returns hardware unique serial number (15 digit in FOMA, 11 digit
* otherwise alphanumeric). Only available with form utn attribute.
* returns null otherwise.
return $this->_serialNumber;
* retuns whether it's FOMA or not
* returns comment on user agent string like 'Google Proxy'. returns null
* returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA
* with <form utn> attribute. returns null otherwise.
* Returns whether a user agent is a GPS model or not.
return in_array($this->_rawModel, $this->_gpsModels);
// {{{ getCarrierShortName()
* returns the short name of the carrier
// {{{ getCarrierLongName()
* returns the long name of the carrier
* Gets the UID of a subscriber.
* @since Method available since Release 1.0.0RC1
return $_SERVER['HTTP_X_DCMGUID'];
// {{{ getBrowserVersion()
* Gets the i-mode browser version.
* @since Method available since Release 1.0.0RC3
* parse main part of HTTP_USER_AGENT string (not FOMA)
* @param string $main main part of HTTP_USER_AGENT string
* @throws Net_UserAgent_Mobile_Error
function _parseMain ($main)
@list ($this->name, $this->version, $this->_rawModel, $cache, $rest) =
if ($this->_rawModel == 'SH505i2') {
$this->_model = 'SH505i';
if (!preg_match('/^c(\d+)$/', $cache, $matches)) {
$this->_cacheSize = (integer) $matches[1 ];
foreach ($rest as $value) {
if (preg_match('/^ser(\w{11})$/', $value, $matches)) {
$this->_serialNumber = $matches[1 ];
if (preg_match('/^(T[CDBJ])$/', $value, $matches)) {
$this->_status = $matches[1 ];
$this->_bandwidth = (integer) $matches[1 ];
if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) {
$this->_displayBytes = "{ $matches[1 ]}*{ $matches[2 ]}";
* parse main part of HTTP_USER_AGENT string (FOMA)
* @param string $foma main part of HTTP_USER_AGENT string
* @throws Net_UserAgent_Mobile_Error
function _parseFOMA ($foma)
if (!preg_match('/^([^(\s]+)/', $foma, $matches)) {
$this->_rawModel = $matches[1 ];
if ($this->_rawModel == 'MST_v_SH2101V') {
$this->_model = 'SH2101V';
if (preg_match('/^[^(\s]+\s?\(([^)]+)\)(?:\(([^)]+)\))?$/', $foma, $matches)) {
if (preg_match('/^compatible/', $matches[1 ])) { // The user-agent is DoCoMo compatible.
$this->_comment = $matches[1 ];
if (count($matches) == 3 ) {
if (preg_match('/^compatible/', $matches[2 ])) { // The user-agent is DoCoMo compatible.
$this->_comment = $matches[2 ];
foreach ($rest as $value) {
$this->_cacheSize = (integer) $matches[1 ];
if (preg_match('/^ser(\w{15})$/', $value, $matches)) {
$this->_serialNumber = $matches[1 ];
if (preg_match('/^([A-Z]+)$/', $value, $matches)) {
$this->_status = $matches[1 ];
if (preg_match('/^icc(\w{20})?$/', $value, $matches)) {
if (count($matches) == 2 ) {
$this->_cardID = $matches[1 ];
if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) {
$this->_displayBytes = "{ $matches[1 ]}*{ $matches[2 ]}";
* c-hanging-comment-ender-p: nil
Documentation generated on Tue, 23 Jun 2009 10:00:04 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.
|