Changeset 18188 for branches/comu-ver2/data/module/Net/UserAgent/Mobile.php
- Timestamp:
- 2009/07/13 21:29:58 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu-ver2/data/module/Net/UserAgent/Mobile.php
r17140 r18188 5 5 * PHP versions 4 and 5 6 6 * 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. 12 30 * 13 31 * @category Networking 14 32 * @package Net_UserAgent_Mobile 15 * @author KUBO Atsuhiro < iteman@users.sourceforge.net>16 * @copyright 2003-200 8 KUBO Atsuhiro <iteman@users.sourceforge.net>17 * @license http://www. php.net/license/3_0.txt PHP License 3.033 * @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 18 36 * @version CVS: $Id$ 19 37 * @since File available since Release 0.1 … … 21 39 22 40 require_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 // }}} 41 require_once dirname(__FILE__) . '/Mobile/Error.php'; 42 35 43 // {{{ GLOBALS 36 44 … … 38 46 * globals for fallback on no match 39 47 * 40 * @global boolean $GLOBALS[' _NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH']48 * @global boolean $GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] 41 49 */ 42 $GLOBALS[' _NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH'] = false;50 $GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] = false; 43 51 44 52 // }}} … … 48 56 * HTTP mobile user agent string parser 49 57 * 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. 53 60 * This package was ported from Perl's HTTP::MobileAgent. 54 61 * See {@link http://search.cpan.org/search?mode=module&query=HTTP-MobileAgent} 55 * The author of the HTTP::MobileAgent module is Tatsuhiko Miyagawa56 * <miyagawa@bulknews.net>57 62 * 58 63 * SYNOPSIS: … … 68 73 * // it's NTT DoCoMo i-mode 69 74 * // see what's available in Net_UserAgent_Mobile_DoCoMo 70 * } elseif ($agent->is Vodafone()) {71 * // it's Vodafone(J-PHONE)72 * // see what's available in Net_UserAgent_Mobile_ Vodafone75 * } elseif ($agent->isSoftBank()) { 76 * // it's SoftBank 77 * // see what's available in Net_UserAgent_Mobile_SoftBank 73 78 * } elseif ($agent->isEZweb()) { 74 79 * // it's KDDI/EZWeb … … 87 92 * @category Networking 88 93 * @package Net_UserAgent_Mobile 89 * @author KUBO Atsuhiro < iteman@users.sourceforge.net>90 * @copyright 2003-200 8 KUBO Atsuhiro <iteman@users.sourceforge.net>91 * @license http://www. php.net/license/3_0.txt PHP License 3.092 * @version Release: 0.31.094 * @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 93 98 * @since Class available since Release 0.1 94 99 */ … … 126 131 * 127 132 * @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 130 136 */ 131 137 function &factory($userAgent = null) 132 138 { 133 139 if (is_null($userAgent)) { 134 $userAgent = $_SERVER['HTTP_USER_AGENT'];140 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 135 141 } 136 142 … … 151 157 152 158 if (!class_exists($class)) { 153 154 159 $file = dirname(__FILE__) . "/Mobile/{$driver}.php"; 155 160 if (!include_once $file) { … … 163 168 } 164 169 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(); 167 174 if (Net_UserAgent_Mobile::isError($error)) { 168 if ($GLOBALS[' _NET_USERAGENT_MOBILE_FALLBACK_ON_NOMATCH']175 if ($GLOBALS['NET_USERAGENT_MOBILE_FallbackOnNomatch'] 169 176 && $error->getCode() == NET_USERAGENT_MOBILE_ERROR_NOMATCH 170 177 ) { … … 173 180 } 174 181 175 $instance = &$error;182 return PEAR::raiseError($error); 176 183 } 177 184 … … 183 190 184 191 /** 185 * creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or 186 * returnsa instance from existent ones192 * creates a new {@link Net_UserAgent_Mobile_Common} subclass instance or returns 193 * a instance from existent ones 187 194 * 188 195 * @param string $userAgent User-Agent string 189 * @return mixed a newly created or a existent Net_UserAgent_Mobile190 * object, or a PEAR error object on error191 * @ 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 192 199 */ 193 200 function &singleton($userAgent = null) … … 200 207 201 208 if (is_null($userAgent)) { 202 $userAgent = $_SERVER['HTTP_USER_AGENT'];209 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 203 210 } 204 211 … … 214 221 215 222 /** 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 218 224 * 219 225 * @param integer $value result code … … 222 228 function isError($value) 223 229 { 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')); 225 233 } 226 234 … … 232 240 * 233 241 * @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 236 243 */ 237 244 function errorMessage($value) … … 260 267 261 268 /** 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. 264 270 * 265 271 * @param string $userAgent … … 286 292 287 293 /** 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. 290 295 * 291 296 * @param string $userAgent … … 296 301 { 297 302 if (is_null($userAgent)) { 298 $userAgent = $_SERVER['HTTP_USER_AGENT'];303 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 299 304 } 300 305 … … 310 315 311 316 /** 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. 314 318 * 315 319 * @param string $userAgent … … 320 324 { 321 325 if (is_null($userAgent)) { 322 $userAgent = $_SERVER['HTTP_USER_AGENT'];326 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 323 327 } 324 328 … … 336 340 337 341 /** 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. 340 343 * 341 344 * @param string $userAgent … … 346 349 { 347 350 if (is_null($userAgent)) { 348 $userAgent = $_SERVER['HTTP_USER_AGENT'];351 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 349 352 } 350 353 … … 374 377 375 378 /** 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. 378 380 * 379 381 * @param string $userAgent … … 384 386 { 385 387 if (is_null($userAgent)) { 386 $userAgent = $_SERVER['HTTP_USER_AGENT'];388 $userAgent = @$_SERVER['HTTP_USER_AGENT']; 387 389 } 388 390 … … 392 394 393 395 return false; 394 }395 396 /**#@-*/397 398 /**#@+399 * @access private400 */401 402 /**#@-*/403 404 // }}}405 }406 407 // }}}408 // {{{ Net_UserAgent_Mobile_Error409 410 /**411 * Net_UserAgent_Mobile_Error implements a class for reporting user412 * agent error messages413 *414 * @category Networking415 * @package Net_UserAgent_Mobile416 * @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.0419 * @version Release: 0.31.0420 * @since Class available since Release 0.1421 */422 class Net_UserAgent_Mobile_Error extends PEAR_Error423 {424 425 // {{{ properties426 427 /**#@+428 * @access public429 */430 431 /**#@-*/432 433 /**#@+434 * @access private435 */436 437 /**#@-*/438 439 /**#@+440 * @access public441 */442 443 // }}}444 // {{{ constructor445 446 /**447 * constructor448 *449 * @param mixed $code Net_UserAgent_Mobile error code, or string450 * with error message.451 * @param integer $mode what 'error mode' to operate in452 * @param integer $level what error level to use for $mode and453 * PEAR_ERROR_TRIGGER454 * @param mixed $userinfo additional user/debug info455 * @access public456 */457 function Net_UserAgent_Mobile_Error($code = NET_USERAGENT_MOBILE_ERROR,458 $mode = PEAR_ERROR_RETURN,459 $level = E_USER_NOTICE,460 $userinfo = null461 )462 {463 if (is_int($code)) {464 $this->PEAR_Error('Net_UserAgent_Mobile Error: ' .465 Net_UserAgent_Mobile::errorMessage($code),466 $code, $mode, $level, $userinfo467 );468 } else {469 $this->PEAR_Error("Net_UserAgent_Mobile Error: $code",470 NET_USERAGENT_MOBILE_ERROR, $mode, $level,471 $userinfo472 );473 }474 396 } 475 397
Note: See TracChangeset
for help on using the changeset viewer.