Ignore:
Timestamp:
2008/03/12 16:43:11 (18 years ago)
Author:
satou
Message:

PEARモジュールの更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2/data/module/Net/UserAgent/Mobile.php

    r15532 r17127  
    1414 * @package    Net_UserAgent_Mobile 
    1515 * @author     KUBO Atsuhiro <[email protected]> 
    16  * @copyright  2003-2007 KUBO Atsuhiro <[email protected]> 
     16 * @copyright  2003-2008 KUBO Atsuhiro <[email protected]> 
    1717 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    1818 * @version    CVS: $Id$ 
     
    2020 */ 
    2121 
    22 require_once dirname(__FILE__) . '/../../PEAR.php'; 
    23 require_once dirname(__FILE__) . '/Mobile/Request.php'; 
     22require_once 'PEAR.php'; 
    2423 
    2524// {{{ constants 
     
    8988 * @package    Net_UserAgent_Mobile 
    9089 * @author     KUBO Atsuhiro <[email protected]> 
    91  * @copyright  2003-2007 KUBO Atsuhiro <[email protected]> 
     90 * @copyright  2003-2008 KUBO Atsuhiro <[email protected]> 
    9291 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    93  * @version    Release: 0.30.0 
     92 * @version    Release: 0.31.0 
    9493 * @since      Class available since Release 0.1 
    9594 */ 
     
    126125     * If no argument is supplied, $_SERVER{'HTTP_*'} is used. 
    127126     * 
    128      * @param mixed $stuff User-Agent string or object that works with 
    129      *     HTTP_Request (not implemented) 
     127     * @param string $userAgent User-Agent string 
    130128     * @return mixed a newly created Net_UserAgent_Mobile object, or a PEAR 
    131129     *     error object on error 
    132      * @see Net_UserAgent_Mobile_Request::factory() 
    133      */ 
    134     function &factory($stuff = null) 
    135     { 
    136         static $mobileRegex; 
    137         if (!isset($mobileRegex)) { 
    138             $docomoRegex    = '^DoCoMo/\d\.\d[ /]'; 
    139             $vodafoneRegex  = '^(?:(?:SoftBank|Vodafone|J-PHONE|Vemulator|J-EMULATOR)/\d\.\d|(?:MOT|MOTEMULATOR)-)'; 
    140             $ezwebRegex     = '^(?:KDDI-[A-Z]+\d+[A-Z]? )?UP\.Browser\/'; 
    141             $airhphoneRegex = '^Mozilla/3\.0\((?:DDIPOCKET|WILLCOM);'; 
    142             $mobileRegex = 
    143                 "(?:($docomoRegex)|($vodafoneRegex)|($ezwebRegex)|($airhphoneRegex))"; 
    144         } 
    145  
    146         $request = &Net_UserAgent_Mobile_Request::factory($stuff); 
     130     */ 
     131    function &factory($userAgent = null) 
     132    { 
     133        if (is_null($userAgent)) { 
     134            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     135        } 
    147136 
    148137        // parse User-Agent string 
    149         $ua = $request->get('User-Agent'); 
    150         $sub = 'NonMobile'; 
    151         if (preg_match("!$mobileRegex!", $ua, $matches)) { 
    152             $sub = @$matches[1] ? 'DoCoMo' : 
    153                 (@$matches[2] ? 'Vodafone' : 
    154                  (@$matches[3] ? 'EZweb' : 'AirHPhone')); 
    155         } 
    156         $className = "Net_UserAgent_Mobile_{$sub}"; 
    157  
    158         if (!class_exists($className)) { 
    159             $file = dirname(__FILE__) . "/Mobile/{$sub}.php"; 
     138        if (Net_UserAgent_Mobile::isDoCoMo($userAgent)) { 
     139            $driver = 'DoCoMo'; 
     140        } elseif (Net_UserAgent_Mobile::isEZweb($userAgent)) { 
     141            $driver = 'EZweb'; 
     142        } elseif (Net_UserAgent_Mobile::isSoftBank($userAgent)) { 
     143            $driver = 'SoftBank'; 
     144        } elseif (Net_UserAgent_Mobile::isWillcom($userAgent)) { 
     145            $driver = 'Willcom'; 
     146        } else { 
     147            $driver = 'NonMobile'; 
     148        } 
     149 
     150        $class = "Net_UserAgent_Mobile_$driver"; 
     151 
     152        if (!class_exists($class)) { 
     153            $file = str_replace('_', '/', $class) . '.php'; 
    160154            if (!include_once $file) { 
    161155                return PEAR::raiseError(null, 
     
    168162        } 
    169163 
    170         $instance = &new $className($request); 
     164        $instance = &new $class($userAgent); 
    171165        $error = &$instance->isError(); 
    172166        if (Net_UserAgent_Mobile::isError($error)) { 
     
    191185     * returns a instance from existent ones 
    192186     * 
    193      * @param mixed $stuff User-Agent string or object that works with 
    194      *     HTTP_Request (not implemented) 
     187     * @param string $userAgent User-Agent string 
    195188     * @return mixed a newly created or a existent Net_UserAgent_Mobile 
    196189     *     object, or a PEAR error object on error 
    197190     * @see Net_UserAgent_Mobile::factory() 
    198191     */ 
    199      function &singleton($stuff = null) 
    200      { 
    201          static $instance; 
    202          if (!isset($instance)) { 
    203              $instance = Net_UserAgent_Mobile::factory($stuff); 
    204          } 
    205  
    206          return $instance; 
    207      } 
     192    function &singleton($userAgent = null) 
     193    { 
     194        static $instances; 
     195 
     196        if (!isset($instances)) { 
     197            $instances = array(); 
     198        } 
     199 
     200        if (is_null($userAgent)) { 
     201            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     202        } 
     203 
     204        if (!array_key_exists($userAgent, $instances)) { 
     205            $instances[$userAgent] = Net_UserAgent_Mobile::factory($userAgent); 
     206        } 
     207 
     208        return $instances[$userAgent]; 
     209    } 
    208210 
    209211    // }}} 
     
    253255    } 
    254256 
     257    // }}} 
     258    // {{{ isMobile() 
     259 
     260    /** 
     261     * Checks whether or not the user agent is mobile by a given user agent 
     262     * string. 
     263     * 
     264     * @param string $userAgent 
     265     * @return boolean 
     266     * @since Method available since Release 0.31.0 
     267     */ 
     268    function isMobile($userAgent = null) 
     269    { 
     270        if (Net_UserAgent_Mobile::isDoCoMo($userAgent)) { 
     271            return true; 
     272        } elseif (Net_UserAgent_Mobile::isEZweb($userAgent)) { 
     273            return true; 
     274        } elseif (Net_UserAgent_Mobile::isSoftBank($userAgent)) { 
     275            return true; 
     276        } elseif (Net_UserAgent_Mobile::isWillcom($userAgent)) { 
     277            return true; 
     278        } 
     279 
     280        return false; 
     281    } 
     282 
     283    // }}} 
     284    // {{{ isDoCoMo() 
     285 
     286    /** 
     287     * Checks whether or not the user agent is DoCoMo by a given user agent 
     288     * string. 
     289     * 
     290     * @param string $userAgent 
     291     * @return boolean 
     292     * @since Method available since Release 0.31.0 
     293     */ 
     294    function isDoCoMo($userAgent = null) 
     295    { 
     296        if (is_null($userAgent)) { 
     297            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     298        } 
     299 
     300        if (preg_match('!^DoCoMo!', $userAgent)) { 
     301            return true; 
     302        } 
     303 
     304        return false; 
     305    } 
     306 
     307    // }}} 
     308    // {{{ isEZweb() 
     309 
     310    /** 
     311     * Checks whether or not the user agent is EZweb by a given user agent 
     312     * string. 
     313     * 
     314     * @param string $userAgent 
     315     * @return boolean 
     316     * @since Method available since Release 0.31.0 
     317     */ 
     318    function isEZweb($userAgent = null) 
     319    { 
     320        if (is_null($userAgent)) { 
     321            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     322        } 
     323 
     324        if (preg_match('!^KDDI-!', $userAgent)) { 
     325            return true; 
     326        } elseif (preg_match('!^UP\.Browser!', $userAgent)) { 
     327            return true; 
     328        } 
     329 
     330        return false; 
     331    } 
     332 
     333    // }}} 
     334    // {{{ isSoftBank() 
     335 
     336    /** 
     337     * Checks whether or not the user agent is SoftBank by a given user agent 
     338     * string. 
     339     * 
     340     * @param string $userAgent 
     341     * @return boolean 
     342     * @since Method available since Release 0.31.0 
     343     */ 
     344    function isSoftBank($userAgent = null) 
     345    { 
     346        if (is_null($userAgent)) { 
     347            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     348        } 
     349 
     350        if (preg_match('!^SoftBank!', $userAgent)) { 
     351            return true; 
     352        } elseif (preg_match('!^Semulator!', $userAgent)) { 
     353            return true; 
     354        } elseif (preg_match('!^Vodafone!', $userAgent)) { 
     355            return true; 
     356        } elseif (preg_match('!^Vemulator!', $userAgent)) { 
     357            return true; 
     358        } elseif (preg_match('!^MOT-!', $userAgent)) { 
     359            return true; 
     360        } elseif (preg_match('!^MOTEMULATOR!', $userAgent)) { 
     361            return true; 
     362        } elseif (preg_match('!^J-PHONE!', $userAgent)) { 
     363            return true; 
     364        } elseif (preg_match('!^J-EMULATOR!', $userAgent)) { 
     365            return true; 
     366        } 
     367 
     368        return false; 
     369    } 
     370 
     371    // }}} 
     372    // {{{ isWillcom() 
     373 
     374    /** 
     375     * Checks whether or not the user agent is Willcom by a given user agent 
     376     * string. 
     377     * 
     378     * @param string $userAgent 
     379     * @return boolean 
     380     * @since Method available since Release 0.31.0 
     381     */ 
     382    function isWillcom($userAgent = null) 
     383    { 
     384        if (is_null($userAgent)) { 
     385            $userAgent = $_SERVER['HTTP_USER_AGENT']; 
     386        } 
     387 
     388        if (preg_match('!^Mozilla/3\.0\((?:DDIPOCKET|WILLCOM);!', $userAgent)) { 
     389            return true; 
     390        } 
     391 
     392        return false; 
     393    } 
     394 
    255395    /**#@-*/ 
    256396 
     
    276416 * @copyright  2003-2007 KUBO Atsuhiro <[email protected]> 
    277417 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    278  * @version    Release: 0.30.0 
     418 * @version    Release: 0.31.0 
    279419 * @since      Class available since Release 0.1 
    280420 */ 
     
    356496 * End: 
    357497 */ 
    358 ?> 
Note: See TracChangeset for help on using the changeset viewer.