2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
7 * Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>,
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
31 * @category Networking
32 * @package Net_UserAgent_Mobile
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
36 * @version CVS: $Id: Common.php 2043 2009-07-03 09:36:18Z fishbone $
37 * @since File available since Release 0.1
39 * @modified-for adjust for magic3 framework
40 * @modified-by naoki hirata(naoki@aplo.co.jp)
41 * @modified-date 2009.7.3
44 //require_once 'Net/UserAgent/Mobile/Error.php';
45 //require_once 'PEAR.php';
46 require_once dirname(__FILE__) . '/Error.php'; // modified by naoki.
48 // {{{ Net_UserAgent_Mobile_Common
51 * Base class that is extended by each user agents implementor
53 * Net_UserAgent_Mobile_Common is a class for mobile user agent
54 * abstraction layer on Net_UserAgent_Mobile.
56 * @category Networking
57 * @package Net_UserAgent_Mobile
58 * @author KUBO Atsuhiro <kubo@iteman.jp>
59 * @copyright 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
60 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
61 * @version Release: 1.0.0
62 * @since Class available since Release 0.1
64 class Net_UserAgent_Mobile_Common
74 * User-Agent name like 'DoCoMo'
80 * User-Agent version number like '1.0'
92 * {@link Net_UserAgent_Mobile_Display} object
93 * @var object {@link Net_UserAgent_Mobile_Display}
98 * {@link Net_UserAgent_Mobile_Error} object for error handling in the constructor
104 * The User-Agent string.
106 * @since Property available since Release 0.31.0
111 * The model name of the user agent.
114 * @since Property available since Release 0.31.0
119 * The raw model name of the user agent.
122 * @since Property available since Release 0.31.0
138 * @param string $userAgent User-Agent string
140 function Net_UserAgent_Mobile_Common($userAgent)
142 $this->_userAgent = $userAgent;
144 $result = $this->parse($userAgent);
145 if (PEAR::isError($result)) {
146 $this->_error = &$result;
154 * Gets a Net_UserAgent_Mobile_Error object.
156 * @param object {@link Net_UserAgent_Mobile_Error} object when setting an error
157 * @return Net_UserAgent_Mobile_Error
158 * @since Method available since Release 1.0.0RC2
162 if (is_null($this->_error)) {
167 return $this->_error;
171 // {{{ getUserAgent()
174 * returns User-Agent string
178 function getUserAgent()
180 return $this->_userAgent;
187 * returns a specified HTTP header
189 * @param string $header
192 function getHeader($header)
194 return @$_SERVER[ 'HTTP_' . str_replace('-', '_', $header) ];
201 * returns User-Agent name like 'DoCoMo'
214 * returns {@link Net_UserAgent_Mobile_Disply} object
216 * @return Net_UserAgent_Mobile_Display
218 function getDisplay()
220 if (is_null($this->_display)) {
221 $this->_display = $this->makeDisplay();
224 return $this->_display;
231 * returns User-Agent version number like '1.0'
235 function getVersion()
237 return $this->version;
244 * generates a warning message for new variants
246 * @throws Net_UserAgent_Mobile_Error
250 return PEAR::raiseError($this->getUserAgent() . ': might be new variants. Please contact the author of Net_UserAgent_Mobile!',
251 NET_USERAGENT_MOBILE_ERROR_NOMATCH,
255 'Net_UserAgent_Mobile_Error'
263 * Parses HTTP_USER_AGENT string.
265 * @param string $userAgent User-Agent string
268 function parse($userAgent) {}
274 * create a new Net_UserAgent_Mobile_Display class instance (should be
275 * implemented in subclasses)
277 * @return Net_UserAgent_Mobile_Display
280 function makeDisplay() {}
286 * returns true if the agent is DoCoMo
299 * returns true if the agent is J-PHONE
312 * returns true if the agent is Vodafone
316 function isVodafone()
325 * returns true if the agent is EZweb
338 * returns true if the agent is AirH"PHONE
342 function isAirHPhone()
351 * returns true if the agent is NonMobile
355 function isNonMobile()
364 * returns true if the agent is TU-Ka
377 * returns true if the agent can speak WAP1 protocol
383 return $this->isEZweb() && !$this->isWAP2();
390 * returns true if the agent can speak WAP2 protocol
396 return $this->isEZweb() && $this->isXHTMLCompliant();
400 // {{{ getCarrierShortName()
403 * returns the short name of the carrier
407 function getCarrierShortName()
413 // {{{ getCarrierLongName()
416 * returns the long name of the carrier
420 function getCarrierLongName()
429 * Returns whether the agent is SoftBank or not.
432 * @since Method available since Release 0.31.0
434 function isSoftBank()
443 * Returns whether the agent is Willcom or not.
446 * @since Method available since Release 0.31.0
457 * Returns the model name of the user agent.
460 * @since Method available since Release 0.31.0
464 if (is_null($this->_model)) {
465 return $this->_rawModel;
467 return $this->_model;
475 * Returns the raw model name of the user agent.
478 * @since Method available since Release 0.31.0
480 function getRawModel()
482 return $this->_rawModel;
489 * Gets the UID of a subscriber.
492 * @since Method available since Release 1.0.0RC1
515 * c-hanging-comment-ender-p: nil
516 * indent-tabs-mode: nil