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