| 1 | <?php |
|---|
| 2 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
|---|
| 3 | // +----------------------------------------------------------------------+ |
|---|
| 4 | // | PHP version 4 | |
|---|
| 5 | // +----------------------------------------------------------------------+ |
|---|
| 6 | // | Copyright (c) 1997-2004 The PHP Group | |
|---|
| 7 | // +----------------------------------------------------------------------+ |
|---|
| 8 | // | This source file is subject to version 3.0 of the PHP license, | |
|---|
| 9 | // | that is bundled with this package in the file LICENSE, and is | |
|---|
| 10 | // | available through the world-wide-web at the following url: | |
|---|
| 11 | // | http://www.php.net/license/3_0.txt. | |
|---|
| 12 | // | If you did not receive a copy of the PHP license and are unable to | |
|---|
| 13 | // | obtain it through the world-wide-web, please send a note to | |
|---|
| 14 | // | [email protected] so we can mail you a copy immediately. | |
|---|
| 15 | // +----------------------------------------------------------------------+ |
|---|
| 16 | // | Authors: KUBO Atsuhiro <[email protected]> | |
|---|
| 17 | // +----------------------------------------------------------------------+ |
|---|
| 18 | // |
|---|
| 19 | // $Id: Common.php,v 1.12 2006/11/07 09:25:14 kuboa Exp $ |
|---|
| 20 | // |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Base class that is extended by each user agents implementor |
|---|
| 24 | * |
|---|
| 25 | * Net_UserAgent_Mobile_Common is a class for mobile user agent |
|---|
| 26 | * abstraction layer on Net_UserAgent_Mobile. |
|---|
| 27 | * |
|---|
| 28 | * @package Net_UserAgent_Mobile |
|---|
| 29 | * @category Networking |
|---|
| 30 | * @abstract |
|---|
| 31 | * @author KUBO Atsuhiro <[email protected]> |
|---|
| 32 | * @access public |
|---|
| 33 | * @version $Revision: 1.12 $ |
|---|
| 34 | */ |
|---|
| 35 | class Net_UserAgent_Mobile_Common extends PEAR |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | // {{{ properties |
|---|
| 39 | |
|---|
| 40 | /**#@+ |
|---|
| 41 | * @access public |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * User-Agent name like 'DoCoMo' |
|---|
| 46 | * @var string |
|---|
| 47 | */ |
|---|
| 48 | var $name = ''; |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * User-Agent version number like '1.0' |
|---|
| 52 | * @var string |
|---|
| 53 | */ |
|---|
| 54 | var $version = ''; |
|---|
| 55 | |
|---|
| 56 | /**#@-*/ |
|---|
| 57 | |
|---|
| 58 | /**#@+ |
|---|
| 59 | * @access private |
|---|
| 60 | */ |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * {@link Net_UserAgent_Mobile_Display} object |
|---|
| 64 | * @var object {@link Net_UserAgent_Mobile_Display} |
|---|
| 65 | */ |
|---|
| 66 | var $_display; |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * Net_UserAgent_Mobile_Request_XXX object |
|---|
| 70 | * @var object {@link Net_UserAgent_Mobile_Request_Env} |
|---|
| 71 | */ |
|---|
| 72 | var $_request; |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * {@link Net_UserAgent_Mobile_Error} object for error handling in the |
|---|
| 76 | * constructor |
|---|
| 77 | * @var object |
|---|
| 78 | **/ |
|---|
| 79 | var $_error = null; |
|---|
| 80 | |
|---|
| 81 | /**#@-*/ |
|---|
| 82 | |
|---|
| 83 | // }}} |
|---|
| 84 | // {{{ constructor |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * constructor |
|---|
| 88 | * |
|---|
| 89 | * @param object $request a {@link Net_UserAgent_Mobile_Request_Env} |
|---|
| 90 | * object |
|---|
| 91 | */ |
|---|
| 92 | function Net_UserAgent_Mobile_Common($request) |
|---|
| 93 | { |
|---|
| 94 | parent::PEAR('Net_UserAgent_Mobile_Error'); |
|---|
| 95 | $this->_request = $request; |
|---|
| 96 | if (Net_UserAgent_Mobile::isError($result = $this->parse())) { |
|---|
| 97 | $this->isError($result); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /**#@+ |
|---|
| 102 | * @access public |
|---|
| 103 | */ |
|---|
| 104 | |
|---|
| 105 | // }}} |
|---|
| 106 | // {{{ isError |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * Returns/set an error when the instance couldn't initialize properly |
|---|
| 110 | * |
|---|
| 111 | * @param object {@link Net_UserAgent_Mobile_Error} object when setting |
|---|
| 112 | * an error |
|---|
| 113 | * @return object {@link Net_UserAgent_Mobile_Error} object |
|---|
| 114 | */ |
|---|
| 115 | function &isError($error = null) |
|---|
| 116 | { |
|---|
| 117 | if ($error !== null) { |
|---|
| 118 | $this->_error = &$error; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | return $this->_error; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | // }}} |
|---|
| 125 | // {{{ raiseError() |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * This method is used to communicate an error and invoke error |
|---|
| 129 | * callbacks etc. Basically a wrapper for PEAR::raiseError without |
|---|
| 130 | * the message string. |
|---|
| 131 | * |
|---|
| 132 | * @param mixed $code integer error code, or a PEAR error object (all |
|---|
| 133 | * other parameters are ignored if this parameter is an object |
|---|
| 134 | * @param int $mode error mode, see PEAR_Error docs |
|---|
| 135 | * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the |
|---|
| 136 | * error level (E_USER_NOTICE etc). If error mode is |
|---|
| 137 | * PEAR_ERROR_CALLBACK, this is the callback function, either as a |
|---|
| 138 | * function name, or as an array of an object and method name. For |
|---|
| 139 | * other error modes this parameter is ignored. |
|---|
| 140 | * @param string $userinfo Extra debug information. Defaults to the last |
|---|
| 141 | * query and native error code. |
|---|
| 142 | * @return object a PEAR error object |
|---|
| 143 | * @see PEAR_Error |
|---|
| 144 | */ |
|---|
| 145 | function &raiseError($code = NET_USERAGENT_MOBILE_ERROR, $mode = null, |
|---|
| 146 | $options = null, $userinfo = null |
|---|
| 147 | ) |
|---|
| 148 | { |
|---|
| 149 | |
|---|
| 150 | // The error is yet a Net_UserAgent_Mobile error object |
|---|
| 151 | if (is_object($code)) { |
|---|
| 152 | $error = &PEAR::raiseError($code, null, null, null, null, null, |
|---|
| 153 | true |
|---|
| 154 | ); |
|---|
| 155 | return $error; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | $error = &PEAR::raiseError(null, $code, $mode, $options, $userinfo, |
|---|
| 159 | 'Net_UserAgent_Mobile_Error', true |
|---|
| 160 | ); |
|---|
| 161 | return $error; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | // }}} |
|---|
| 165 | // {{{ getUserAgent() |
|---|
| 166 | |
|---|
| 167 | /** |
|---|
| 168 | * returns User-Agent string |
|---|
| 169 | * |
|---|
| 170 | * @return string |
|---|
| 171 | */ |
|---|
| 172 | function getUserAgent() |
|---|
| 173 | { |
|---|
| 174 | return $this->getHeader('User-Agent'); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | // }}} |
|---|
| 178 | // {{{ getHeader() |
|---|
| 179 | |
|---|
| 180 | /** |
|---|
| 181 | * returns a specified HTTP header |
|---|
| 182 | * |
|---|
| 183 | * @param string $header |
|---|
| 184 | * @return string |
|---|
| 185 | */ |
|---|
| 186 | function getHeader($header) |
|---|
| 187 | { |
|---|
| 188 | return $this->_request->get($header); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | // }}} |
|---|
| 192 | // {{{ getName() |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | * returns User-Agent name like 'DoCoMo' |
|---|
| 196 | * |
|---|
| 197 | * @return string |
|---|
| 198 | */ |
|---|
| 199 | function getName() |
|---|
| 200 | { |
|---|
| 201 | return $this->name; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | // }}} |
|---|
| 205 | // {{{ getDisplay() |
|---|
| 206 | |
|---|
| 207 | /** |
|---|
| 208 | * returns {@link Net_UserAgent_Mobile_Disply} object |
|---|
| 209 | * |
|---|
| 210 | * @return object a {@link Net_UserAgent_Mobile_Display} object, or a |
|---|
| 211 | * PEAR error object on error |
|---|
| 212 | * @see Net_UserAgent_Mobile_Display |
|---|
| 213 | */ |
|---|
| 214 | function getDisplay() |
|---|
| 215 | { |
|---|
| 216 | if (!is_object($this->_display)) { |
|---|
| 217 | $this->_display = $this->makeDisplay(); |
|---|
| 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 | * @return object a PEAR error object |
|---|
| 242 | */ |
|---|
| 243 | function noMatch() |
|---|
| 244 | { |
|---|
| 245 | return $this->raiseError(NET_USERAGENT_MOBILE_ERROR_NOMATCH, null, |
|---|
| 246 | null, $this->getUserAgent() . |
|---|
| 247 | ': might be new variants. Please contact the author of Net_UserAgent_Mobile!' |
|---|
| 248 | ); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | // }}} |
|---|
| 252 | // {{{ parse() |
|---|
| 253 | |
|---|
| 254 | /** |
|---|
| 255 | * parse HTTP_USER_AGENT string (should be implemented in subclasses) |
|---|
| 256 | * |
|---|
| 257 | * @abstract |
|---|
| 258 | */ |
|---|
| 259 | function parse() |
|---|
| 260 | { |
|---|
| 261 | die(); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | // }}} |
|---|
| 265 | // {{{ makeDisplay() |
|---|
| 266 | |
|---|
| 267 | /** |
|---|
| 268 | * create a new Net_UserAgent_Mobile_Display class instance (should be |
|---|
| 269 | * implemented in subclasses) |
|---|
| 270 | * |
|---|
| 271 | * @abstract |
|---|
| 272 | */ |
|---|
| 273 | function makeDisplay() |
|---|
| 274 | { |
|---|
| 275 | die(); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | // }}} |
|---|
| 279 | // {{{ isDoCoMo() |
|---|
| 280 | |
|---|
| 281 | /** |
|---|
| 282 | * returns true if the agent is DoCoMo |
|---|
| 283 | * |
|---|
| 284 | * @return boolean |
|---|
| 285 | */ |
|---|
| 286 | function isDoCoMo() |
|---|
| 287 | { |
|---|
| 288 | return false; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | // }}} |
|---|
| 292 | // {{{ isJPhone() |
|---|
| 293 | |
|---|
| 294 | /** |
|---|
| 295 | * returns true if the agent is J-PHONE |
|---|
| 296 | * |
|---|
| 297 | * @return boolean |
|---|
| 298 | */ |
|---|
| 299 | function isJPhone() |
|---|
| 300 | { |
|---|
| 301 | return false; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | // }}} |
|---|
| 305 | // {{{ isVodafone() |
|---|
| 306 | |
|---|
| 307 | /** |
|---|
| 308 | * returns true if the agent is Vodafone |
|---|
| 309 | * |
|---|
| 310 | * @return boolean |
|---|
| 311 | */ |
|---|
| 312 | function isVodafone() |
|---|
| 313 | { |
|---|
| 314 | return false; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | // }}} |
|---|
| 318 | // {{{ isEZweb() |
|---|
| 319 | |
|---|
| 320 | /** |
|---|
| 321 | * returns true if the agent is EZweb |
|---|
| 322 | * |
|---|
| 323 | * @return boolean |
|---|
| 324 | */ |
|---|
| 325 | function isEZweb() |
|---|
| 326 | { |
|---|
| 327 | return false; |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | // }}} |
|---|
| 331 | // {{{ isAirHPhone() |
|---|
| 332 | |
|---|
| 333 | /** |
|---|
| 334 | * returns true if the agent is AirH"PHONE |
|---|
| 335 | * |
|---|
| 336 | * @return boolean |
|---|
| 337 | */ |
|---|
| 338 | function isAirHPhone() |
|---|
| 339 | { |
|---|
| 340 | return false; |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | // }}} |
|---|
| 344 | // {{{ isNonMobile() |
|---|
| 345 | |
|---|
| 346 | /** |
|---|
| 347 | * returns true if the agent is NonMobile |
|---|
| 348 | * |
|---|
| 349 | * @return boolean |
|---|
| 350 | */ |
|---|
| 351 | function isNonMobile() |
|---|
| 352 | { |
|---|
| 353 | return false; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | // }}} |
|---|
| 357 | // {{{ isTUKa() |
|---|
| 358 | |
|---|
| 359 | /** |
|---|
| 360 | * returns true if the agent is TU-Ka |
|---|
| 361 | * |
|---|
| 362 | * @return boolean |
|---|
| 363 | */ |
|---|
| 364 | function isTUKa() |
|---|
| 365 | { |
|---|
| 366 | return false; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | // }}} |
|---|
| 370 | // {{{ isWAP1() |
|---|
| 371 | |
|---|
| 372 | /** |
|---|
| 373 | * returns true if the agent can speak WAP1 protocol |
|---|
| 374 | * |
|---|
| 375 | * @return boolean |
|---|
| 376 | */ |
|---|
| 377 | function isWAP1() |
|---|
| 378 | { |
|---|
| 379 | return $this->isEZweb() && !$this->isWAP2(); |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | // }}} |
|---|
| 383 | // {{{ isWAP2() |
|---|
| 384 | |
|---|
| 385 | /** |
|---|
| 386 | * returns true if the agent can speak WAP2 protocol |
|---|
| 387 | * |
|---|
| 388 | * @return boolean |
|---|
| 389 | */ |
|---|
| 390 | function isWAP2() |
|---|
| 391 | { |
|---|
| 392 | return $this->isEZweb() && $this->isXHTMLCompliant(); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | // }}} |
|---|
| 396 | // {{{ getCarrierShortName() |
|---|
| 397 | |
|---|
| 398 | /** |
|---|
| 399 | * returns the short name of the carrier |
|---|
| 400 | * |
|---|
| 401 | * @abstract |
|---|
| 402 | */ |
|---|
| 403 | function getCarrierShortName() |
|---|
| 404 | { |
|---|
| 405 | die(); |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | // }}} |
|---|
| 409 | // {{{ getCarrierLongName() |
|---|
| 410 | |
|---|
| 411 | /** |
|---|
| 412 | * returns the long name of the carrier |
|---|
| 413 | * |
|---|
| 414 | * @abstract |
|---|
| 415 | */ |
|---|
| 416 | function getCarrierLongName() |
|---|
| 417 | { |
|---|
| 418 | die(); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | /**#@-*/ |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | /* |
|---|
| 425 | * Local Variables: |
|---|
| 426 | * mode: php |
|---|
| 427 | * coding: iso-8859-1 |
|---|
| 428 | * tab-width: 4 |
|---|
| 429 | * c-basic-offset: 4 |
|---|
| 430 | * c-hanging-comment-ender-p: nil |
|---|
| 431 | * indent-tabs-mode: nil |
|---|
| 432 | * End: |
|---|
| 433 | */ |
|---|
| 434 | ?> |
|---|