Source for file Mobile.php
Documentation is available at Mobile.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: KUBO Atsuhiro <kubo@isite.co.jp> |
// +----------------------------------------------------------------------+
// $Id: Mobile.php,v 1.21 2005/07/27 08:15:27 kuboa Exp $
require_once('PEAR.php');
require_once(dirname (__FILE__ ) . '/Mobile/Request.php');
* constants for error handling
define('NET_USERAGENT_MOBILE_OK', 1 );
define('NET_USERAGENT_MOBILE_ERROR', -1 );
define('NET_USERAGENT_MOBILE_ERROR_NOMATCH', -2 );
define('NET_USERAGENT_MOBILE_ERROR_NOT_FOUND', -3 );
* globals for fallback on no match
* @name $_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH
* @global boolean $GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH']
$GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH'] = false;
* HTTP mobile user agent string parser
* Net_UserAgent_Mobile parses HTTP_USER_AGENT strings of (mainly Japanese)
* mobile HTTP user agents. It'll be useful in page dispatching by user
* This package was ported from Perl's HTTP::MobileAgent.
* See {@link http://search.cpan.org/search?mode=module&query=HTTP-MobileAgent}
* The author of the HTTP::MobileAgent module is Tatsuhiko Miyagawa
* <miyagawa@bulknews.net>
* require_once('Net/UserAgent/Mobile.php');
* $agent = &Net_UserAgent_Mobile::factory($agent_string);
* // or $agent = &Net_UserAgent_Mobile::factory(); // to get from $_SERVER
* if ($agent->isDoCoMo()) {
* // or if ($agent->getName() == 'DoCoMo')
* // or if (strtolower(get_class($agent)) == 'http_mobileagent_docomo')
* // it's NTT DoCoMo i-mode
* // see what's available in Net_UserAgent_Mobile_DoCoMo
* } elseif ($agent->isVodafone()) {
* // it's Vodafone(J-PHONE)
* // see what's available in Net_UserAgent_Mobile_Vodafone
* } elseif ($agent->isEZweb()) {
* // see what's available in Net_UserAgent_Mobile_EZweb
* // $agent is Net_UserAgent_Mobile_NonMobile
* $display = $agent->getDisplay(); // Net_UserAgent_Mobile_Display
* if ($display->isColor()) {
* @package Net_UserAgent_Mobile
* @author KUBO Atsuhiro <kubo@isite.co.jp>
* @version $Revision: 1.21 $
* create a new {@link Net_UserAgent_Mobile_Common} subclass instance
* parses HTTP headers and constructs {@link Net_UserAgent_Mobile_Common}
* If no argument is supplied, $_SERVER{'HTTP_*'} is used.
* @param mixed $stuff User-Agent string or object that works with
* HTTP_Request (not implemented)
* @return mixed a newly created Net_UserAgent_Mobile object, or a PEAR
* @see Net_UserAgent_Mobile_Request::factory()
if (!isset ($mobileRegex)) {
$docomoRegex = '^DoCoMo/\d\.\d[ /]';
$vodafoneRegex = '^(?:(?:Vodafone|J-PHONE)/\d\.\d|MOT-)';
$ezwebRegex = '^(?:KDDI-[A-Z]+\d+[A-Z]? )?UP\.Browser\/';
$airhphoneRegex = '^Mozilla/3\.0\(DDIPOCKET;';
" (?:($docomoRegex)|($vodafoneRegex)|($ezwebRegex)|($airhphoneRegex))";
// parse User-Agent string
$ua = $request->get ('User-Agent');
if (preg_match(" !$mobileRegex!" , $ua, $matches)) {
$sub = @$matches[1 ] ? 'DoCoMo' :
(@$matches[2 ] ? 'Vodafone' :
(@$matches[3 ] ? 'EZweb' : 'AirHPhone'));
$className = " Net_UserAgent_Mobile_{$sub}";
$include = dirname(__FILE__ ) . " /Mobile/{$sub}.php";
return PEAR ::raiseError (null ,
" Unable to read the $include file" ,
'Net_UserAgent_Mobile_Error', true
if (!include_once($include)) {
return PEAR ::raiseError (null ,
" Unable to include the $include file" ,
'Net_UserAgent_Mobile_Error', true
$instance = &new $className($request);
$error = &$instance->isError ();
if ($GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH']
* creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or
* returns a instance from existent ones
* @param mixed $stuff User-Agent string or object that works with
* HTTP_Request (not implemented)
* @return mixed a newly created or a existent Net_UserAgent_Mobile
* object, or a PEAR error object on error
* @see Net_UserAgent_Mobile::factory()
* tell whether a result code from a Net_UserAgent_Mobile method
* @param integer $value result code
* @return boolean whether $value is an {@link Net_UserAgent_Mobile_Error}
return is_a($value, 'Net_UserAgent_Mobile_Error');
* return a textual error message for a Net_UserAgent_Mobile error code
* @param integer $value error code
* @return string error message, or false if the error code was not
if (!isset ($errorMessages)) {
$value = $value->getCode ();
return isset ($errorMessages[$value]) ?
* Net_UserAgent_Mobile_Error implements a class for reporting user
* @package Net_UserAgent_Mobile
* @author KUBO Atsuhiro <kubo@isite.co.jp>
* @version $Revision: 1.21 $
* @param mixed $code Net_UserAgent_Mobile error code, or string
* @param integer $mode what 'error mode' to operate in
* @param integer $level what error level to use for $mode and
* @param mixed $userinfo additional user/debug info
$mode = PEAR_ERROR_RETURN ,
$this->PEAR_Error ('Net_UserAgent_Mobile Error: ' .
$code, $mode, $level, $userinfo
$this->PEAR_Error (" Net_UserAgent_Mobile Error: $code" ,
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 11 Mar 2019 14:16:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|