| 1 | <?php |
|---|
| 2 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
|---|
| 3 | |
|---|
| 4 | /** |
|---|
| 5 | * PHP versions 4 and 5 |
|---|
| 6 | * |
|---|
| 7 | * Copyright (c) 2003-2009 KUBO Atsuhiro <[email protected]>, |
|---|
| 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. |
|---|
| 30 | * |
|---|
| 31 | * @category Networking |
|---|
| 32 | * @package Net_UserAgent_Mobile |
|---|
| 33 | * @author KUBO Atsuhiro <[email protected]> |
|---|
| 34 | * @copyright 2003-2009 KUBO Atsuhiro <[email protected]> |
|---|
| 35 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|---|
| 36 | * @version CVS: $Id$ |
|---|
| 37 | * @since File available since Release 0.1 |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | require_once dirname(__FILE__) . '/Error.php'; |
|---|
| 41 | require_once dirname(__FILE__) . '/../../../PEAR.php'; |
|---|
| 42 | |
|---|
| 43 | // {{{ Net_UserAgent_Mobile_Common |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | * Base class that is extended by each user agents implementor |
|---|
| 47 | * |
|---|
| 48 | * Net_UserAgent_Mobile_Common is a class for mobile user agent |
|---|
| 49 | * abstraction layer on Net_UserAgent_Mobile. |
|---|
| 50 | * |
|---|
| 51 | * @category Networking |
|---|
| 52 | * @package Net_UserAgent_Mobile |
|---|
| 53 | * @author KUBO Atsuhiro <[email protected]> |
|---|
| 54 | * @copyright 2003-2009 KUBO Atsuhiro <[email protected]> |
|---|
| 55 | * @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|---|
| 56 | * @version Release: 1.0.0 |
|---|
| 57 | * @since Class available since Release 0.1 |
|---|
| 58 | */ |
|---|
| 59 | class Net_UserAgent_Mobile_Common |
|---|
| 60 | { |
|---|
| 61 | |
|---|
| 62 | // {{{ properties |
|---|
| 63 | |
|---|
| 64 | /**#@+ |
|---|
| 65 | * @access public |
|---|
| 66 | */ |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * User-Agent name like 'DoCoMo' |
|---|
| 70 | * @var string |
|---|
| 71 | */ |
|---|
| 72 | var $name; |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * User-Agent version number like '1.0' |
|---|
| 76 | * @var string |
|---|
| 77 | */ |
|---|
| 78 | var $version; |
|---|
| 79 | |
|---|
| 80 | /**#@-*/ |
|---|
| 81 | |
|---|
| 82 | /**#@+ |
|---|
| 83 | * @access private |
|---|
| 84 | */ |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * {@link Net_UserAgent_Mobile_Display} object |
|---|
| 88 | * @var object {@link Net_UserAgent_Mobile_Display} |
|---|
| 89 | */ |
|---|
| 90 | var $_display; |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * {@link Net_UserAgent_Mobile_Error} object for error handling in the constructor |
|---|
| 94 | * @var object |
|---|
| 95 | **/ |
|---|
| 96 | var $_error; |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * The User-Agent string. |
|---|
| 100 | * @var string |
|---|
| 101 | * @since Property available since Release 0.31.0 |
|---|
| 102 | **/ |
|---|
| 103 | var $_userAgent; |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * The model name of the user agent. |
|---|
| 107 | * |
|---|
| 108 | * @var string |
|---|
| 109 | * @since Property available since Release 0.31.0 |
|---|
| 110 | */ |
|---|
| 111 | var $_model; |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * The raw model name of the user agent. |
|---|
| 115 | * |
|---|
| 116 | * @var string |
|---|
| 117 | * @since Property available since Release 0.31.0 |
|---|
| 118 | */ |
|---|
| 119 | var $_rawModel; |
|---|
| 120 | |
|---|
| 121 | /**#@-*/ |
|---|
| 122 | |
|---|
| 123 | /**#@+ |
|---|
| 124 | * @access public |
|---|
| 125 | */ |
|---|
| 126 | |
|---|
| 127 | // }}} |
|---|
| 128 | // {{{ constructor |
|---|
| 129 | |
|---|
| 130 | /** |
|---|
| 131 | * constructor |
|---|
| 132 | * |
|---|
| 133 | * @param string $userAgent User-Agent string |
|---|
| 134 | */ |
|---|
| 135 | function Net_UserAgent_Mobile_Common($userAgent) |
|---|
| 136 | { |
|---|
| 137 | $this->_userAgent = $userAgent; |
|---|
| 138 | |
|---|
| 139 | $result = $this->parse($userAgent); |
|---|
| 140 | if (PEAR::isError($result)) { |
|---|
| 141 | $this->_error = &$result; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | // }}} |
|---|
| 146 | // {{{ getError |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * Gets a Net_UserAgent_Mobile_Error object. |
|---|
| 150 | * |
|---|
| 151 | * @param object {@link Net_UserAgent_Mobile_Error} object when setting an error |
|---|
| 152 | * @return Net_UserAgent_Mobile_Error |
|---|
| 153 | * @since Method available since Release 1.0.0RC2 |
|---|
| 154 | */ |
|---|
| 155 | function &getError() |
|---|
| 156 | { |
|---|
| 157 | if (is_null($this->_error)) { |
|---|
| 158 | $return = null; |
|---|
| 159 | return $return; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | return $this->_error; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | // }}} |
|---|
| 166 | // {{{ getUserAgent() |
|---|
| 167 | |
|---|
| 168 | /** |
|---|
| 169 | * returns User-Agent string |
|---|
| 170 | * |
|---|
| 171 | * @return string |
|---|
| 172 | */ |
|---|
| 173 | function getUserAgent() |
|---|
| 174 | { |
|---|
| 175 | return $this->_userAgent; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | // }}} |
|---|
| 179 | // {{{ getHeader() |
|---|
| 180 | |
|---|
| 181 | /** |
|---|
| 182 | * returns a specified HTTP header |
|---|
| 183 | * |
|---|
| 184 | * @param string $header |
|---|
| 185 | * @return string |
|---|
| 186 | */ |
|---|
| 187 | function getHeader($header) |
|---|
| 188 | { |
|---|
| 189 | return @$_SERVER[ 'HTTP_' . str_replace('-', '_', $header) ]; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | // }}} |
|---|
| 193 | // {{{ getName() |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | * returns User-Agent name like 'DoCoMo' |
|---|
| 197 | * |
|---|
| 198 | * @return string |
|---|
| 199 | */ |
|---|
| 200 | function getName() |
|---|
| 201 | { |
|---|
| 202 | return $this->name; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | // }}} |
|---|
| 206 | // {{{ getDisplay() |
|---|
| 207 | |
|---|
| 208 | /** |
|---|
| 209 | * returns {@link Net_UserAgent_Mobile_Disply} object |
|---|
| 210 | * |
|---|
| 211 | * @return Net_UserAgent_Mobile_Display |
|---|
| 212 | */ |
|---|
| 213 | function getDisplay() |
|---|
| 214 | { |
|---|
| 215 | if (is_null($this->_display)) { |
|---|
| 216 | $this->_display = $this->makeDisplay(); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | return $this->_display; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | // }}} |
|---|
| 223 | // {{{ getVersion() |
|---|
| 224 | |
|---|
| 225 | /** |
|---|
| 226 | * returns User-Agent version number like '1.0' |
|---|
| 227 | * |
|---|
| 228 | * @return string |
|---|
| 229 | */ |
|---|
| 230 | function getVersion() |
|---|
| 231 | { |
|---|
| 232 | return $this->version; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | // }}} |
|---|
| 236 | // {{{ noMatch() |
|---|
| 237 | |
|---|
| 238 | /** |
|---|
| 239 | * generates a warning message for new variants |
|---|
| 240 | * |
|---|
| 241 | * @throws Net_UserAgent_Mobile_Error |
|---|
| 242 | */ |
|---|
| 243 | function noMatch() |
|---|
| 244 | { |
|---|
| 245 | return PEAR::raiseError($this->getUserAgent() . ': might be new variants. Please contact the author of Net_UserAgent_Mobile!', |
|---|
| 246 | NET_USERAGENT_MOBILE_ERROR_NOMATCH, |
|---|
| 247 | null, |
|---|
| 248 | null, |
|---|
| 249 | null, |
|---|
| 250 | 'Net_UserAgent_Mobile_Error' |
|---|
| 251 | ); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | // }}} |
|---|
| 255 | // {{{ parse() |
|---|
| 256 | |
|---|
| 257 | /** |
|---|
| 258 | * Parses HTTP_USER_AGENT string. |
|---|
| 259 | * |
|---|
| 260 | * @param string $userAgent User-Agent string |
|---|
| 261 | * @abstract |
|---|
| 262 | */ |
|---|
| 263 | function parse($userAgent) {} |
|---|
| 264 | |
|---|
| 265 | // }}} |
|---|
| 266 | // {{{ makeDisplay() |
|---|
| 267 | |
|---|
| 268 | /** |
|---|
| 269 | * create a new Net_UserAgent_Mobile_Display class instance (should be |
|---|
| 270 | * implemented in subclasses) |
|---|
| 271 | * |
|---|
| 272 | * @return Net_UserAgent_Mobile_Display |
|---|
| 273 | * @abstract |
|---|
| 274 | */ |
|---|
| 275 | function makeDisplay() {} |
|---|
| 276 | |
|---|
| 277 | // }}} |
|---|
| 278 | // {{{ isDoCoMo() |
|---|
| 279 | |
|---|
| 280 | /** |
|---|
| 281 | * returns true if the agent is DoCoMo |
|---|
| 282 | * |
|---|
| 283 | * @return boolean |
|---|
| 284 | */ |
|---|
| 285 | function isDoCoMo() |
|---|
| 286 | { |
|---|
| 287 | return false; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | // }}} |
|---|
| 291 | // {{{ isJPhone() |
|---|
| 292 | |
|---|
| 293 | /** |
|---|
| 294 | * returns true if the agent is J-PHONE |
|---|
| 295 | * |
|---|
| 296 | * @return boolean |
|---|
| 297 | */ |
|---|
| 298 | function isJPhone() |
|---|
| 299 | { |
|---|
| 300 | return false; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | // }}} |
|---|
| 304 | // {{{ isVodafone() |
|---|
| 305 | |
|---|
| 306 | /** |
|---|
| 307 | * returns true if the agent is Vodafone |
|---|
| 308 | * |
|---|
| 309 | * @return boolean |
|---|
| 310 | */ |
|---|
| 311 | function isVodafone() |
|---|
| 312 | { |
|---|
| 313 | return false; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | // }}} |
|---|
| 317 | // {{{ isEZweb() |
|---|
| 318 | |
|---|
| 319 | /** |
|---|
| 320 | * returns true if the agent is EZweb |
|---|
| 321 | * |
|---|
| 322 | * @return boolean |
|---|
| 323 | */ |
|---|
| 324 | function isEZweb() |
|---|
| 325 | { |
|---|
| 326 | return false; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | // }}} |
|---|
| 330 | // {{{ isAirHPhone() |
|---|
| 331 | |
|---|
| 332 | /** |
|---|
| 333 | * returns true if the agent is AirH"PHONE |
|---|
| 334 | * |
|---|
| 335 | * @return boolean |
|---|
| 336 | */ |
|---|
| 337 | function isAirHPhone() |
|---|
| 338 | { |
|---|
| 339 | return false; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | // }}} |
|---|
| 343 | // {{{ isNonMobile() |
|---|
| 344 | |
|---|
| 345 | /** |
|---|
| 346 | * returns true if the agent is NonMobile |
|---|
| 347 | * |
|---|
| 348 | * @return boolean |
|---|
| 349 | */ |
|---|
| 350 | function isNonMobile() |
|---|
| 351 | { |
|---|
| 352 | return false; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | // }}} |
|---|
| 356 | // {{{ isTUKa() |
|---|
| 357 | |
|---|
| 358 | /** |
|---|
| 359 | * returns true if the agent is TU-Ka |
|---|
| 360 | * |
|---|
| 361 | * @return boolean |
|---|
| 362 | */ |
|---|
| 363 | function isTUKa() |
|---|
| 364 | { |
|---|
| 365 | return false; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | // }}} |
|---|
| 369 | // {{{ isWAP1() |
|---|
| 370 | |
|---|
| 371 | /** |
|---|
| 372 | * returns true if the agent can speak WAP1 protocol |
|---|
| 373 | * |
|---|
| 374 | * @return boolean |
|---|
| 375 | */ |
|---|
| 376 | function isWAP1() |
|---|
| 377 | { |
|---|
| 378 | return $this->isEZweb() && !$this->isWAP2(); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | // }}} |
|---|
| 382 | // {{{ isWAP2() |
|---|
| 383 | |
|---|
| 384 | /** |
|---|
| 385 | * returns true if the agent can speak WAP2 protocol |
|---|
| 386 | * |
|---|
| 387 | * @return boolean |
|---|
| 388 | */ |
|---|
| 389 | function isWAP2() |
|---|
| 390 | { |
|---|
| 391 | return $this->isEZweb() && $this->isXHTMLCompliant(); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | // }}} |
|---|
| 395 | // {{{ getCarrierShortName() |
|---|
| 396 | |
|---|
| 397 | /** |
|---|
| 398 | * returns the short name of the carrier |
|---|
| 399 | * |
|---|
| 400 | * @abstract |
|---|
| 401 | */ |
|---|
| 402 | function getCarrierShortName() |
|---|
| 403 | { |
|---|
| 404 | die(); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | // }}} |
|---|
| 408 | // {{{ getCarrierLongName() |
|---|
| 409 | |
|---|
| 410 | /** |
|---|
| 411 | * returns the long name of the carrier |
|---|
| 412 | * |
|---|
| 413 | * @abstract |
|---|
| 414 | */ |
|---|
| 415 | function getCarrierLongName() |
|---|
| 416 | { |
|---|
| 417 | die(); |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | // }}} |
|---|
| 421 | // {{{ isSoftBank() |
|---|
| 422 | |
|---|
| 423 | /** |
|---|
| 424 | * Returns whether the agent is SoftBank or not. |
|---|
| 425 | * |
|---|
| 426 | * @return boolean |
|---|
| 427 | * @since Method available since Release 0.31.0 |
|---|
| 428 | */ |
|---|
| 429 | function isSoftBank() |
|---|
| 430 | { |
|---|
| 431 | return false; |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | // }}} |
|---|
| 435 | // {{{ isWillcom() |
|---|
| 436 | |
|---|
| 437 | /** |
|---|
| 438 | * Returns whether the agent is Willcom or not. |
|---|
| 439 | * |
|---|
| 440 | * @return boolean |
|---|
| 441 | * @since Method available since Release 0.31.0 |
|---|
| 442 | */ |
|---|
| 443 | function isWillcom() |
|---|
| 444 | { |
|---|
| 445 | return false; |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | // }}} |
|---|
| 449 | // {{{ isSmartphone() |
|---|
| 450 | |
|---|
| 451 | /** |
|---|
| 452 | * Returns whether the agent is Smartphone or not. |
|---|
| 453 | * |
|---|
| 454 | * @return boolean |
|---|
| 455 | * @since Method available since Release 0.31.0 |
|---|
| 456 | */ |
|---|
| 457 | function isSmartphone() |
|---|
| 458 | { |
|---|
| 459 | return false; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | // }}} |
|---|
| 464 | // {{{ getModel() |
|---|
| 465 | |
|---|
| 466 | /** |
|---|
| 467 | * Returns the model name of the user agent. |
|---|
| 468 | * |
|---|
| 469 | * @return string |
|---|
| 470 | * @since Method available since Release 0.31.0 |
|---|
| 471 | */ |
|---|
| 472 | function getModel() |
|---|
| 473 | { |
|---|
| 474 | if (is_null($this->_model)) { |
|---|
| 475 | return $this->_rawModel; |
|---|
| 476 | } else { |
|---|
| 477 | return $this->_model; |
|---|
| 478 | } |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | // }}} |
|---|
| 482 | // {{{ getRawModel() |
|---|
| 483 | |
|---|
| 484 | /** |
|---|
| 485 | * Returns the raw model name of the user agent. |
|---|
| 486 | * |
|---|
| 487 | * @return string |
|---|
| 488 | * @since Method available since Release 0.31.0 |
|---|
| 489 | */ |
|---|
| 490 | function getRawModel() |
|---|
| 491 | { |
|---|
| 492 | return $this->_rawModel; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | // }}} |
|---|
| 496 | // {{{ getUID() |
|---|
| 497 | |
|---|
| 498 | /** |
|---|
| 499 | * Gets the UID of a subscriber. |
|---|
| 500 | * |
|---|
| 501 | * @return string |
|---|
| 502 | * @since Method available since Release 1.0.0RC1 |
|---|
| 503 | */ |
|---|
| 504 | function getUID() {} |
|---|
| 505 | |
|---|
| 506 | /**#@-*/ |
|---|
| 507 | |
|---|
| 508 | /**#@+ |
|---|
| 509 | * @access private |
|---|
| 510 | */ |
|---|
| 511 | |
|---|
| 512 | /**#@-*/ |
|---|
| 513 | |
|---|
| 514 | // }}} |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | // }}} |
|---|
| 518 | |
|---|
| 519 | /* |
|---|
| 520 | * Local Variables: |
|---|
| 521 | * mode: php |
|---|
| 522 | * coding: iso-8859-1 |
|---|
| 523 | * tab-width: 4 |
|---|
| 524 | * c-basic-offset: 4 |
|---|
| 525 | * c-hanging-comment-ender-p: nil |
|---|
| 526 | * indent-tabs-mode: nil |
|---|
| 527 | * End: |
|---|
| 528 | */ |
|---|