Ignore:
Timestamp:
2009/07/13 21:29:58 (15 years ago)
Author:
AMUAMU
Message:

#403 関連 Net_UserAgent_Mobileを1.0.0(stable)にアップデート

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/module/Net/UserAgent/Mobile.php

    r17140 r18188  
    55 * PHP versions 4 and 5 
    66 * 
    7  * LICENSE: This source file is subject to version 3.0 of the PHP license 
    8  * that is available through the world-wide-web at the following URI: 
    9  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of 
    10  * the PHP License and are unable to obtain it through the web, please 
    11  * send a note to license@php.net so we can mail you a copy immediately. 
     7 * Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>, 
     8 * All rights reserved. 
     9 * 
     10 * Redistribution and use in source and binary forms, with or without 
     11 * modification, are permitted provided that the following conditions are met: 
     12 * 
     13 *     * Redistributions of source code must retain the above copyright 
     14 *       notice, this list of conditions and the following disclaimer. 
     15 *     * Redistributions in binary form must reproduce the above copyright 
     16 *       notice, this list of conditions and the following disclaimer in the 
     17 *       documentation and/or other materials provided with the distribution. 
     18 * 
     19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
     20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
     23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
     24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
     25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
     26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
     27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     29 * POSSIBILITY OF SUCH DAMAGE. 
    1230 * 
    1331 * @category   Networking 
    1432 * @package    Net_UserAgent_Mobile 
    15  * @author     KUBO Atsuhiro <iteman@users.sourceforge.net> 
    16  * @copyright  2003-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    17  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
     33 * @author     KUBO Atsuhiro <kubo@iteman.jp> 
     34 * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp> 
     35 * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License 
    1836 * @version    CVS: $Id$ 
    1937 * @since      File available since Release 0.1 
     
    2139 
    2240require_once dirname(__FILE__) . '/../../PEAR.php'; 
    23  
    24 // {{{ constants 
    25  
    26 /** 
    27  * Constants for error handling. 
    28  */ 
    29 define('NET_USERAGENT_MOBILE_OK',               1); 
    30 define('NET_USERAGENT_MOBILE_ERROR',           -1); 
    31 define('NET_USERAGENT_MOBILE_ERROR_NOMATCH',   -2); 
    32 define('NET_USERAGENT_MOBILE_ERROR_NOT_FOUND', -3); 
    33  
    34 // }}} 
     41require_once dirname(__FILE__) . '/Mobile/Error.php'; 
     42 
    3543// {{{ GLOBALS 
    3644 
     
    3846 * globals for fallback on no match 
    3947 * 
    40  * @global boolean $GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH'] 
     48 * @global boolean $GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] 
    4149 */ 
    42 $GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH'] = false; 
     50$GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] = false; 
    4351 
    4452// }}} 
     
    4856 * HTTP mobile user agent string parser 
    4957 * 
    50  * Net_UserAgent_Mobile parses HTTP_USER_AGENT strings of (mainly Japanese) 
    51  * mobile HTTP user agents. It'll be useful in page dispatching by user 
    52  * agents. 
     58 * Net_UserAgent_Mobile parses HTTP_USER_AGENT strings of (mainly Japanese) mobile 
     59 * HTTP user agents. It'll be useful in page dispatching by user agents. 
    5360 * This package was ported from Perl's HTTP::MobileAgent. 
    5461 * See {@link http://search.cpan.org/search?mode=module&query=HTTP-MobileAgent} 
    55  * The author of the HTTP::MobileAgent module is Tatsuhiko Miyagawa 
    56  * <miyagawa@bulknews.net> 
    5762 * 
    5863 * SYNOPSIS: 
     
    6873 *     // it's NTT DoCoMo i-mode 
    6974 *     // see what's available in Net_UserAgent_Mobile_DoCoMo 
    70  * } elseif ($agent->isVodafone()) { 
    71  *     // it's Vodafone(J-PHONE) 
    72  *     // see what's available in Net_UserAgent_Mobile_Vodafone 
     75 * } elseif ($agent->isSoftBank()) { 
     76 *     // it's SoftBank 
     77 *     // see what's available in Net_UserAgent_Mobile_SoftBank 
    7378 * } elseif ($agent->isEZweb()) { 
    7479 *     // it's KDDI/EZWeb 
     
    8792 * @category   Networking 
    8893 * @package    Net_UserAgent_Mobile 
    89  * @author     KUBO Atsuhiro <iteman@users.sourceforge.net> 
    90  * @copyright  2003-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    91  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    92  * @version    Release: 0.31.0 
     94 * @author     KUBO Atsuhiro <kubo@iteman.jp> 
     95 * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp> 
     96 * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License 
     97 * @version    Release: 1.0.0 
    9398 * @since      Class available since Release 0.1 
    9499 */ 
     
    126131     * 
    127132     * @param string $userAgent User-Agent string 
    128      * @return mixed a newly created Net_UserAgent_Mobile object, or a PEAR 
    129      *     error object on error 
     133     * @return Net_UserAgent_Mobile_Common a newly created or an existing 
     134     *     Net_UserAgent_Mobile_Common object 
     135     * @throws Net_UserAgent_Mobile_Error 
    130136     */ 
    131137    function &factory($userAgent = null) 
    132138    { 
    133139        if (is_null($userAgent)) { 
    134             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     140            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    135141        } 
    136142 
     
    151157 
    152158        if (!class_exists($class)) { 
    153              
    154159            $file = dirname(__FILE__) . "/Mobile/{$driver}.php"; 
    155160            if (!include_once $file) { 
     
    163168        } 
    164169 
    165         $instance = &new $class($userAgent); 
    166         $error = &$instance->isError(); 
     170        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 
     171        $instance = new $class($userAgent); 
     172        PEAR::staticPopErrorHandling(); 
     173        $error = &$instance->getError(); 
    167174        if (Net_UserAgent_Mobile::isError($error)) { 
    168             if ($GLOBALS['_NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH'] 
     175            if ($GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] 
    169176                && $error->getCode() == NET_USERAGENT_MOBILE_ERROR_NOMATCH 
    170177                ) { 
     
    173180            } 
    174181 
    175             $instance = &$error; 
     182            return PEAR::raiseError($error); 
    176183        } 
    177184 
     
    183190 
    184191    /** 
    185      * creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or 
    186      * returns a instance from existent ones 
     192     * creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or returns 
     193     * a instance from existent ones 
    187194     * 
    188195     * @param string $userAgent User-Agent string 
    189      * @return mixed a newly created or a existent Net_UserAgent_Mobile 
    190      *     object, or a PEAR error object on error 
    191      * @see Net_UserAgent_Mobile::factory() 
     196     * @return Net_UserAgent_Mobile_Common a newly created or an existing 
     197     *     Net_UserAgent_Mobile_Common object 
     198     * @throws Net_UserAgent_Mobile_Error 
    192199     */ 
    193200    function &singleton($userAgent = null) 
     
    200207 
    201208        if (is_null($userAgent)) { 
    202             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     209            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    203210        } 
    204211 
     
    214221 
    215222    /** 
    216      * tell whether a result code from a Net_UserAgent_Mobile method 
    217      * is an error 
     223     * tell whether a result code from a Net_UserAgent_Mobile method is an error 
    218224     * 
    219225     * @param integer $value result code 
     
    222228    function isError($value) 
    223229    { 
    224         return is_a($value, 'Net_UserAgent_Mobile_Error'); 
     230        return is_object($value) 
     231            && (strtolower(get_class($value)) == strtolower('Net_UserAgent_Mobile_Error') 
     232                || is_subclass_of($value, 'Net_UserAgent_Mobile_Error')); 
    225233    } 
    226234 
     
    232240     * 
    233241     * @param integer $value error code 
    234      * @return string error message, or false if the error code was not 
    235      *     recognized 
     242     * @return string error message, or null if the error code was not recognized 
    236243     */ 
    237244    function errorMessage($value) 
     
    260267 
    261268    /** 
    262      * Checks whether or not the user agent is mobile by a given user agent 
    263      * string. 
     269     * Checks whether or not the user agent is mobile by a given user agent string. 
    264270     * 
    265271     * @param string $userAgent 
     
    286292 
    287293    /** 
    288      * Checks whether or not the user agent is DoCoMo by a given user agent 
    289      * string. 
     294     * Checks whether or not the user agent is DoCoMo by a given user agent string. 
    290295     * 
    291296     * @param string $userAgent 
     
    296301    { 
    297302        if (is_null($userAgent)) { 
    298             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     303            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    299304        } 
    300305 
     
    310315 
    311316    /** 
    312      * Checks whether or not the user agent is EZweb by a given user agent 
    313      * string. 
     317     * Checks whether or not the user agent is EZweb by a given user agent string. 
    314318     * 
    315319     * @param string $userAgent 
     
    320324    { 
    321325        if (is_null($userAgent)) { 
    322             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     326            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    323327        } 
    324328 
     
    336340 
    337341    /** 
    338      * Checks whether or not the user agent is SoftBank by a given user agent 
    339      * string. 
     342     * Checks whether or not the user agent is SoftBank by a given user agent string. 
    340343     * 
    341344     * @param string $userAgent 
     
    346349    { 
    347350        if (is_null($userAgent)) { 
    348             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     351            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    349352        } 
    350353 
     
    374377 
    375378    /** 
    376      * Checks whether or not the user agent is Willcom by a given user agent 
    377      * string. 
     379     * Checks whether or not the user agent is Willcom by a given user agent string. 
    378380     * 
    379381     * @param string $userAgent 
     
    384386    { 
    385387        if (is_null($userAgent)) { 
    386             $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     388            $userAgent = @$_SERVER['HTTP_USER_AGENT']; 
    387389        } 
    388390 
     
    392394 
    393395        return false; 
    394     } 
    395  
    396     /**#@-*/ 
    397  
    398     /**#@+ 
    399      * @access private 
    400      */ 
    401  
    402     /**#@-*/ 
    403  
    404     // }}} 
    405 } 
    406  
    407 // }}} 
    408 // {{{ Net_UserAgent_Mobile_Error 
    409  
    410 /** 
    411  * Net_UserAgent_Mobile_Error implements a class for reporting user 
    412  * agent error messages 
    413  * 
    414  * @category   Networking 
    415  * @package    Net_UserAgent_Mobile 
    416  * @author     KUBO Atsuhiro <iteman@users.sourceforge.net> 
    417  * @copyright  2003-2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    418  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    419  * @version    Release: 0.31.0 
    420  * @since      Class available since Release 0.1 
    421  */ 
    422 class Net_UserAgent_Mobile_Error extends PEAR_Error 
    423 { 
    424  
    425     // {{{ properties 
    426  
    427     /**#@+ 
    428      * @access public 
    429      */ 
    430  
    431     /**#@-*/ 
    432  
    433     /**#@+ 
    434      * @access private 
    435      */ 
    436  
    437     /**#@-*/ 
    438  
    439     /**#@+ 
    440      * @access public 
    441      */ 
    442  
    443     // }}} 
    444     // {{{ constructor 
    445  
    446     /** 
    447      * constructor 
    448      * 
    449      * @param mixed   $code     Net_UserAgent_Mobile error code, or string 
    450      *     with error message. 
    451      * @param integer $mode     what 'error mode' to operate in 
    452      * @param integer $level    what error level to use for $mode and 
    453      *     PEAR_ERROR_TRIGGER 
    454      * @param mixed   $userinfo additional user/debug info 
    455      * @access public 
    456      */ 
    457     function Net_UserAgent_Mobile_Error($code = NET_USERAGENT_MOBILE_ERROR, 
    458                                         $mode = PEAR_ERROR_RETURN, 
    459                                         $level = E_USER_NOTICE, 
    460                                         $userinfo = null 
    461                                         ) 
    462     { 
    463         if (is_int($code)) { 
    464             $this->PEAR_Error('Net_UserAgent_Mobile Error: ' . 
    465                               Net_UserAgent_Mobile::errorMessage($code), 
    466                               $code, $mode, $level, $userinfo 
    467                               ); 
    468         } else { 
    469             $this->PEAR_Error("Net_UserAgent_Mobile Error: $code", 
    470                               NET_USERAGENT_MOBILE_ERROR, $mode, $level, 
    471                               $userinfo 
    472                               ); 
    473         } 
    474396    } 
    475397 
Note: See TracChangeset for help on using the changeset viewer.