OSDN Git Service

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