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$
|
---|
19 | * @since File available since Release 0.20.0
|
---|
20 | */
|
---|
21 |
|
---|
22 | require_once dirname(__FILE__) . '/Common.php';
|
---|
23 | require_once dirname(__FILE__) . '/Display.php';
|
---|
24 |
|
---|
25 | // {{{ Net_UserAgent_Mobile_Vodafone
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Vodafone implementation
|
---|
29 | *
|
---|
30 | * Net_UserAgent_Mobile_Vodafone is a subclass of
|
---|
31 | * {@link Net_UserAgent_Mobile_Common}, which implements Vodafone user agents.
|
---|
32 | *
|
---|
33 | * SYNOPSIS:
|
---|
34 | * <code>
|
---|
35 | * require_once 'Net/UserAgent/Mobile.php';
|
---|
36 | *
|
---|
37 | * $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
|
---|
38 | * $agent = &Net_UserAgent_Mobile::factory();
|
---|
39 | *
|
---|
40 | * printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
|
---|
41 | * printf("Version: %s\n", $agent->getVersion()); // 2.0
|
---|
42 | * printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
|
---|
43 | * if ($agent->isPacketCompliant()) {
|
---|
44 | * print "Packet is compliant.\n"; // false
|
---|
45 | * }
|
---|
46 | *
|
---|
47 | * // only availabe in Java compliant
|
---|
48 | * // e.g.) 'J-PHONE/4.0/J-SH51/SNXXXXXXXXX SH/0001a Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0'
|
---|
49 | * printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
|
---|
50 | * printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
|
---|
51 | * printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
|
---|
52 | *
|
---|
53 | * $info = $agent->getJavaInfo(); // array
|
---|
54 | * foreach ($info as $key => $value) {
|
---|
55 | * print "$key: $value\n";
|
---|
56 | * }
|
---|
57 | * </code>
|
---|
58 | *
|
---|
59 | * @category Networking
|
---|
60 | * @package Net_UserAgent_Mobile
|
---|
61 | * @author KUBO Atsuhiro <iteman@users.sourceforge.net>
|
---|
62 | * @copyright 2003-2007 KUBO Atsuhiro <iteman@users.sourceforge.net>
|
---|
63 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
---|
64 | * @version Release: 0.30.0
|
---|
65 | * @link http://developers.vodafone.jp/dp/tool_dl/web/useragent.php
|
---|
66 | * @link http://developers.vodafone.jp/dp/tool_dl/web/position.php
|
---|
67 | * @see Net_UserAgent_Mobile_Common
|
---|
68 | * @since Class available since Release 0.20.0
|
---|
69 | */
|
---|
70 | class Net_UserAgent_Mobile_Vodafone extends Net_UserAgent_Mobile_Common
|
---|
71 | {
|
---|
72 |
|
---|
73 | // {{{ properties
|
---|
74 |
|
---|
75 | /**#@+
|
---|
76 | * @access public
|
---|
77 | */
|
---|
78 |
|
---|
79 | /**#@-*/
|
---|
80 |
|
---|
81 | /**#@+
|
---|
82 | * @access private
|
---|
83 | */
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * name of the model like 'J-DN02'
|
---|
87 | * @var string
|
---|
88 | */
|
---|
89 | var $_model = '';
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * whether the agent is packet connection complicant or not
|
---|
93 | * @var boolean
|
---|
94 | */
|
---|
95 | var $_packetCompliant = false;
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * terminal unique serial number
|
---|
99 | * @var string
|
---|
100 | */
|
---|
101 | var $_serialNumber = null;
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * vendor code like 'SH'
|
---|
105 | * @var string
|
---|
106 | */
|
---|
107 | var $_vendor = '';
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * vendor version like '0001a'
|
---|
111 | * @var string
|
---|
112 | */
|
---|
113 | var $_vendorVersion = null;
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Java profiles
|
---|
117 | * @var array
|
---|
118 | */
|
---|
119 | var $_javaInfo = array();
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * whether the agent is 3G
|
---|
123 | * @var boolean
|
---|
124 | */
|
---|
125 | var $_is3G = true;
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * the name of the mobile phone
|
---|
129 | * @var string
|
---|
130 | */
|
---|
131 | var $_msname = '';
|
---|
132 |
|
---|
133 | /**#@-*/
|
---|
134 |
|
---|
135 | /**#@+
|
---|
136 | * @access public
|
---|
137 | */
|
---|
138 |
|
---|
139 | // }}}
|
---|
140 | // {{{ isJPhone()
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * returns true
|
---|
144 | *
|
---|
145 | * @return boolean
|
---|
146 | */
|
---|
147 | function isJPhone()
|
---|
148 | {
|
---|
149 | return true;
|
---|
150 | }
|
---|
151 |
|
---|
152 | // }}}
|
---|
153 | // {{{ isVodafone()
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * returns true
|
---|
157 | *
|
---|
158 | * @return boolean
|
---|
159 | */
|
---|
160 | function isVodafone()
|
---|
161 | {
|
---|
162 | return true;
|
---|
163 | }
|
---|
164 |
|
---|
165 | // }}}
|
---|
166 | // {{{ parse()
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * parse HTTP_USER_AGENT string
|
---|
170 | *
|
---|
171 | * @return mixed void, or a PEAR error object on error
|
---|
172 | */
|
---|
173 | function parse()
|
---|
174 | {
|
---|
175 | $agent = explode(' ', $this->getUserAgent());
|
---|
176 | preg_match('!^(?:(SoftBank|Vodafone|J-PHONE)/\d\.\d|MOT-)!',
|
---|
177 | $agent[0], $matches
|
---|
178 | );
|
---|
179 | if (count($matches) > 1) {
|
---|
180 | $carrier = $matches[1];
|
---|
181 | } else {
|
---|
182 | $carrier = 'Motorola';
|
---|
183 | }
|
---|
184 |
|
---|
185 | switch ($carrier) {
|
---|
186 | case 'Vodafone':
|
---|
187 | case 'SoftBank':
|
---|
188 | $result = $this->_parseVodafone($agent);
|
---|
189 | break;
|
---|
190 | case 'J-PHONE':
|
---|
191 | $result = $this->_parseJphone($agent);
|
---|
192 | break;
|
---|
193 | case 'Motorola':
|
---|
194 | $result = $this->_parseMotorola($agent);
|
---|
195 | break;
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (Net_UserAgent_Mobile::isError($result)) {
|
---|
199 | return $result;
|
---|
200 | }
|
---|
201 |
|
---|
202 | $this->_msname = $this->getHeader('x-jphone-msname');
|
---|
203 | }
|
---|
204 |
|
---|
205 | // }}}
|
---|
206 | // {{{ makeDisplay()
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * create a new {@link Net_UserAgent_Mobile_Display} class instance
|
---|
210 | *
|
---|
211 | * @return object a newly created {@link Net_UserAgent_Mobile_Display}
|
---|
212 | * object
|
---|
213 | * @see Net_UserAgent_Mobile_Display
|
---|
214 | */
|
---|
215 | function makeDisplay()
|
---|
216 | {
|
---|
217 | @list($width, $height) =
|
---|
218 | explode('*', $this->getHeader('x-jphone-display'));
|
---|
219 | $color = false;
|
---|
220 | $depth = 0;
|
---|
221 | if ($color_string = $this->getHeader('x-jphone-color')) {
|
---|
222 | preg_match('!^([CG])(\d+)$!', $color_string, $matches);
|
---|
223 | $color = $matches[1] === 'C' ? true : false;
|
---|
224 | $depth = $matches[2];
|
---|
225 | }
|
---|
226 | return new Net_UserAgent_Mobile_Display(array(
|
---|
227 | 'width' => $width,
|
---|
228 | 'height' => $height,
|
---|
229 | 'depth' => $depth,
|
---|
230 | 'color' => $color)
|
---|
231 | );
|
---|
232 | }
|
---|
233 |
|
---|
234 | // }}}
|
---|
235 | // {{{ getModel()
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * returns name of the model like 'J-DN02'
|
---|
239 | *
|
---|
240 | * @return string
|
---|
241 | */
|
---|
242 | function getModel()
|
---|
243 | {
|
---|
244 | return $this->_model;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // }}}
|
---|
248 | // {{{ isPacketCompliant()
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * returns whether the agent is packet connection complicant or not
|
---|
252 | *
|
---|
253 | * @return boolean
|
---|
254 | */
|
---|
255 | function isPacketCompliant()
|
---|
256 | {
|
---|
257 | return $this->_packetCompliant;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // }}}
|
---|
261 | // {{{ getSerialNumber()
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * return terminal unique serial number. returns null if user forbids to
|
---|
265 | * send his/her serial number.
|
---|
266 | *
|
---|
267 | * @return string
|
---|
268 | */
|
---|
269 | function getSerialNumber()
|
---|
270 | {
|
---|
271 | return $this->_serialNumber;
|
---|
272 | }
|
---|
273 |
|
---|
274 | // }}}
|
---|
275 | // {{{ getVendor()
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * returns vendor code like 'SH'
|
---|
279 | *
|
---|
280 | * @return string
|
---|
281 | */
|
---|
282 | function getVendor()
|
---|
283 | {
|
---|
284 | return $this->_vendor;
|
---|
285 | }
|
---|
286 |
|
---|
287 | // }}}
|
---|
288 | // {{{ getVendorVersion()
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * returns vendor version like '0001a'. returns null if unknown.
|
---|
292 | *
|
---|
293 | * @return string
|
---|
294 | */
|
---|
295 | function getVendorVersion()
|
---|
296 | {
|
---|
297 | return $this->_vendorVersion;
|
---|
298 | }
|
---|
299 |
|
---|
300 | // }}}
|
---|
301 | // {{{ getJavaInfo()
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * returns array of Java profiles
|
---|
305 | *
|
---|
306 | * Array structure is something like:
|
---|
307 | *
|
---|
308 | * - 'Profile' => 'MIDP-1.0',
|
---|
309 | * - 'Configuration' => 'CLDC-1.0',
|
---|
310 | * - 'Ext-Profile' => 'JSCL-1.1.0'
|
---|
311 | *
|
---|
312 | * @return array
|
---|
313 | */
|
---|
314 | function getJavaInfo()
|
---|
315 | {
|
---|
316 | return $this->_javaInfo;
|
---|
317 | }
|
---|
318 |
|
---|
319 | // }}}
|
---|
320 | // {{{ getCarrierShortName()
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * returns the short name of the carrier
|
---|
324 | *
|
---|
325 | * @return string
|
---|
326 | */
|
---|
327 | function getCarrierShortName()
|
---|
328 | {
|
---|
329 | return 'V';
|
---|
330 | }
|
---|
331 |
|
---|
332 | // }}}
|
---|
333 | // {{{ getCarrierLongName()
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * returns the long name of the carrier
|
---|
337 | *
|
---|
338 | * @return string
|
---|
339 | */
|
---|
340 | function getCarrierLongName()
|
---|
341 | {
|
---|
342 | return 'Vodafone';
|
---|
343 | }
|
---|
344 |
|
---|
345 | // }}}
|
---|
346 | // {{{ isTypeC()
|
---|
347 |
|
---|
348 | /**
|
---|
349 | * returns true if the type is C
|
---|
350 | *
|
---|
351 | * @return boolean
|
---|
352 | */
|
---|
353 | function isTypeC()
|
---|
354 | {
|
---|
355 | if ($this->_is3G || !preg_match('!^[32]\.!', $this->version)) {
|
---|
356 | return false;
|
---|
357 | }
|
---|
358 |
|
---|
359 | return true;
|
---|
360 | }
|
---|
361 |
|
---|
362 | // }}}
|
---|
363 | // {{{ isTypeP()
|
---|
364 |
|
---|
365 | /**
|
---|
366 | * returns true if the type is P
|
---|
367 | *
|
---|
368 | * @return boolean
|
---|
369 | */
|
---|
370 | function isTypeP()
|
---|
371 | {
|
---|
372 | if ($this->_is3G || !preg_match('!^4\.!', $this->version)) {
|
---|
373 | return false;
|
---|
374 | }
|
---|
375 |
|
---|
376 | return true;
|
---|
377 | }
|
---|
378 |
|
---|
379 | // }}}
|
---|
380 | // {{{ isTypeW()
|
---|
381 |
|
---|
382 | /**
|
---|
383 | * returns true if the type is W
|
---|
384 | *
|
---|
385 | * @return boolean
|
---|
386 | */
|
---|
387 | function isTypeW()
|
---|
388 | {
|
---|
389 | if ($this->_is3G || !preg_match('!^5\.!', $this->version)) {
|
---|
390 | return false;
|
---|
391 | }
|
---|
392 |
|
---|
393 | return true;
|
---|
394 | }
|
---|
395 |
|
---|
396 | // }}}
|
---|
397 | // {{{ isType3GC()
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * returns true if the type is 3GC
|
---|
401 | *
|
---|
402 | * @return boolean
|
---|
403 | */
|
---|
404 | function isType3GC()
|
---|
405 | {
|
---|
406 | return $this->_is3G;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // }}}
|
---|
410 | // {{{ getMsname()
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * returns the name of the mobile phone
|
---|
414 | *
|
---|
415 | * @return string the name of the mobile phone
|
---|
416 | */
|
---|
417 | function getMsname()
|
---|
418 | {
|
---|
419 | return $this->_msname;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /**#@-*/
|
---|
423 |
|
---|
424 | /**#@+
|
---|
425 | * @access private
|
---|
426 | */
|
---|
427 |
|
---|
428 | // }}}
|
---|
429 | // {{{ _parseVodafone()
|
---|
430 |
|
---|
431 | /**
|
---|
432 | * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
|
---|
433 | *
|
---|
434 | * @param array $agent parts of the User-Agent string
|
---|
435 | * @return mixed void, or a PEAR error object on error
|
---|
436 | */
|
---|
437 | function _parseVodafone(&$agent)
|
---|
438 | {
|
---|
439 | $count = count($agent);
|
---|
440 | $this->_packetCompliant = true;
|
---|
441 |
|
---|
442 | // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
|
---|
443 | // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
|
---|
444 | // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
|
---|
445 | @list($this->name, $this->version, $this->_model, $modelVersion,
|
---|
446 | $serialNumber) = explode('/', $agent[0]);
|
---|
447 | if ($serialNumber) {
|
---|
448 | if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
|
---|
449 | return $this->noMatch();
|
---|
450 | }
|
---|
451 | $this->_serialNumber = $matches[1];
|
---|
452 | }
|
---|
453 |
|
---|
454 | if (!preg_match('!^([a-z]+)((?:[a-z]|\d){4})$!i', $modelVersion, $matches)) {
|
---|
455 | return $this->noMatch();
|
---|
456 | }
|
---|
457 |
|
---|
458 | $this->_vendor = $matches[1];
|
---|
459 | $this->_vendorVersion = $matches[2];
|
---|
460 |
|
---|
461 | for ($i = 2; $i < $count; ++$i) {
|
---|
462 | list($key, $value) = explode('/', $agent[$i]);
|
---|
463 | $this->_javaInfo[$key] = $value;
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | // }}}
|
---|
468 | // {{{ _parseJphone()
|
---|
469 |
|
---|
470 | /**
|
---|
471 | * parse HTTP_USER_AGENT string for the ancient agent
|
---|
472 | *
|
---|
473 | * @param array $agent parts of the User-Agent string
|
---|
474 | * @return mixed void, or a PEAR error object on error
|
---|
475 | */
|
---|
476 | function _parseJphone(&$agent)
|
---|
477 | {
|
---|
478 | $count = count($agent);
|
---|
479 | $this->_is3G = false;
|
---|
480 |
|
---|
481 | if ($count > 1) {
|
---|
482 |
|
---|
483 | // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
|
---|
484 | $this->_packetCompliant = true;
|
---|
485 | @list($this->name, $this->version, $this->_model,
|
---|
486 | $serialNumber) = explode('/', $agent[0]);
|
---|
487 | if ($serialNumber) {
|
---|
488 | if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
|
---|
489 | return $this->noMatch();
|
---|
490 | }
|
---|
491 | $this->_serialNumber = $matches[1];
|
---|
492 | }
|
---|
493 | list($this->_vendor, $this->_vendorVersion) =
|
---|
494 | explode('/', $agent[1]);
|
---|
495 | for ($i = 2; $i < $count; ++$i) {
|
---|
496 | list($key, $value) = explode('/', $agent[$i]);
|
---|
497 | $this->_javaInfo[$key] = $value;
|
---|
498 | }
|
---|
499 | } else {
|
---|
500 |
|
---|
501 | // J-PHONE/2.0/J-DN02
|
---|
502 | @list($this->name, $this->version, $model) =
|
---|
503 | explode('/', $agent[0]);
|
---|
504 | $this->_model = (string)$model;
|
---|
505 | if ($this->_model) {
|
---|
506 | if (preg_match('!V\d+([A-Z]+)!', $this->_model, $matches)) {
|
---|
507 | $this->_vendor = $matches[1];
|
---|
508 | } elseif (preg_match('!J-([A-Z]+)!', $this->_model, $matches)) {
|
---|
509 | $this->_vendor = $matches[1];
|
---|
510 | }
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | // }}}
|
---|
516 | // {{{ _parseMotorola()
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
|
---|
520 | *
|
---|
521 | * @param array $agent parts of the User-Agent string
|
---|
522 | * @return mixed void, or a PEAR error object on error
|
---|
523 | */
|
---|
524 | function _parseMotorola(&$agent)
|
---|
525 | {
|
---|
526 | $count = count($agent);
|
---|
527 | $this->_packetCompliant = true;
|
---|
528 | $this->_vendor = 'MOT';
|
---|
529 |
|
---|
530 | // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
|
---|
531 | list($name, $this->_vendorVersion) = explode('/', $agent[0]);
|
---|
532 | $this->_model = substr(strrchr($name, '-'), 1);
|
---|
533 |
|
---|
534 | for ($i = 2; $i < $count; ++$i) {
|
---|
535 | list($key, $value) = explode('/', $agent[$i]);
|
---|
536 | $this->_javaInfo[$key] = $value;
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | /**#@-*/
|
---|
541 |
|
---|
542 | // }}}
|
---|
543 | }
|
---|
544 |
|
---|
545 | // }}}
|
---|
546 |
|
---|
547 | /*
|
---|
548 | * Local Variables:
|
---|
549 | * mode: php
|
---|
550 | * coding: iso-8859-1
|
---|
551 | * tab-width: 4
|
---|
552 | * c-basic-offset: 4
|
---|
553 | * c-hanging-comment-ender-p: nil
|
---|
554 | * indent-tabs-mode: nil
|
---|
555 | * End:
|
---|
556 | */
|
---|
557 | ?>
|
---|