Source for file Mobile.php
Documentation is available at Mobile.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: Mobile.php,v 1.1 2009/05/26 08:48:16 kuboa Exp $
* @since File available since Release 0.1
require_once 'Net/UserAgent/Mobile/Error.php';
* globals for fallback on no match
* @global boolean $GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch']
$GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] = false;
// {{{ Net_UserAgent_Mobile
* 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 agents.
* This package was ported from Perl's HTTP::MobileAgent.
* See {@link http://search.cpan.org/search?mode=module&query=HTTP-MobileAgent}
* 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->isSoftBank()) {
* // see what's available in Net_UserAgent_Mobile_SoftBank
* } 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@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
* @since Class available since Release 0.1
* 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 string $userAgent User-Agent string
* @return Net_UserAgent_Mobile_Common a newly created or an existing
* Net_UserAgent_Mobile_Common object
* @throws Net_UserAgent_Mobile_Error
function &factory($userAgent = null )
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
// parse User-Agent string
$class = " Net_UserAgent_Mobile_$driver";
if (!include_once $file) {
return PEAR ::raiseError (null ,
" Unable to include the $file file" ,
'Net_UserAgent_Mobile_Error', true
PEAR ::staticPushErrorHandling (PEAR_ERROR_RETURN );
$instance = new $class($userAgent);
PEAR ::staticPopErrorHandling ();
$error = &$instance->getError ();
if ($GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch']
return PEAR ::raiseError ($error);
* creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or returns
* a instance from existent ones
* @param string $userAgent User-Agent string
* @return Net_UserAgent_Mobile_Common a newly created or an existing
* Net_UserAgent_Mobile_Common object
* @throws Net_UserAgent_Mobile_Error
if (!isset ($instances)) {
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
return $instances[$userAgent];
* tell whether a result code from a Net_UserAgent_Mobile method is an error
* @param integer $value result code
* @return boolean whether $value is an {@link 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 null if the error code was not recognized
if (!isset ($errorMessages)) {
$value = $value->getCode ();
return isset ($errorMessages[$value]) ?
* Checks whether or not the user agent is mobile by a given user agent string.
* @param string $userAgent
* @since Method available since Release 0.31.0
* Checks whether or not the user agent is DoCoMo by a given user agent string.
* @param string $userAgent
* @since Method available since Release 0.31.0
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
* Checks whether or not the user agent is EZweb by a given user agent string.
* @param string $userAgent
* @since Method available since Release 0.31.0
function isEZweb($userAgent = null )
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
} elseif (preg_match('!^UP\.Browser!', $userAgent)) {
* Checks whether or not the user agent is SoftBank by a given user agent string.
* @param string $userAgent
* @since Method available since Release 0.31.0
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
} elseif (preg_match('!^Semulator!', $userAgent)) {
} elseif (preg_match('!^Vodafone!', $userAgent)) {
} elseif (preg_match('!^Vemulator!', $userAgent)) {
} elseif (preg_match('!^MOTEMULATOR!', $userAgent)) {
} elseif (preg_match('!^J-EMULATOR!', $userAgent)) {
* Checks whether or not the user agent is Willcom by a given user agent string.
* @param string $userAgent
* @since Method available since Release 0.31.0
$userAgent = @$_SERVER['HTTP_USER_AGENT'];
if (preg_match('!^Mozilla/3\.0\((?:DDIPOCKET|WILLCOM);!', $userAgent)) {
* c-hanging-comment-ender-p: nil
Documentation generated on Tue, 23 Jun 2009 10:00:05 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.
|