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-2008 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 | * @link http://www.nttdocomo.co.jp/service/imode/make/content/spec/useragent/index.html |
---|
20 | * @see Net_UserAgent_Mobile_Common |
---|
21 | * @since File available since Release 0.1 |
---|
22 | */ |
---|
23 | |
---|
24 | require_once dirname(__FILE__) . '/Common.php'; |
---|
25 | require_once dirname(__FILE__) . '/Display.php'; |
---|
26 | require_once dirname(__FILE__) . '/DoCoMoDisplayMap.php'; |
---|
27 | |
---|
28 | // {{{ Net_UserAgent_Mobile_DoCoMo |
---|
29 | |
---|
30 | /** |
---|
31 | * NTT DoCoMo implementation |
---|
32 | * |
---|
33 | * Net_UserAgent_Mobile_DoCoMo is a subclass of |
---|
34 | * {@link Net_UserAgent_Mobile_Common}, which implements NTT docomo i-mode |
---|
35 | * user agents. |
---|
36 | * |
---|
37 | * SYNOPSIS: |
---|
38 | * <code> |
---|
39 | * require_once 'Net/UserAgent/Mobile.php'; |
---|
40 | * |
---|
41 | * $_SERVER['HTTP_USER_AGENT'] = 'DoCoMo/1.0/P502i/c10'; |
---|
42 | * $agent = &Net_UserAgent_Mobile::factory(); |
---|
43 | * |
---|
44 | * printf("Name: %s\n", $agent->getName()); // 'DoCoMo' |
---|
45 | * printf("Version: %s\n", $agent->getVersion()); // 1.0 |
---|
46 | * printf("HTML version: %s\n", $agent->getHTMLVersion()); // 2.0 |
---|
47 | * printf("Model: %s\n", $agent->getModel()); // 'P502i' |
---|
48 | * printf("Cache: %dk\n", $agent->getCacheSize()); // 10 |
---|
49 | * if ($agent->isFOMA()) { |
---|
50 | * print "FOMA\n"; // false |
---|
51 | * } |
---|
52 | * printf("Vendor: %s\n", $agent->getVendor()); // 'P' |
---|
53 | * printf("Series: %s\n", $agent->getSeries()); // '502i' |
---|
54 | * |
---|
55 | * // only available with <form utn> |
---|
56 | * // e.g.) 'DoCoMo/1.0/P503i/c10/serNMABH200331'; |
---|
57 | * printf("Serial: %s\n", $agent->getSerialNumber()); // 'NMABH200331' |
---|
58 | * |
---|
59 | * // e.g.) 'DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)'; |
---|
60 | * printf("Serial: %s\n", $agent->getSerialNumber()); // '0123456789abcde' |
---|
61 | * printf("Card ID: %s\n", $agent->getCardID()); // '01234567890123456789' |
---|
62 | * |
---|
63 | * // e.g.) 'DoCoMo/1.0/P502i (Google CHTML Proxy/1.0)' |
---|
64 | * printf("Comment: %s\n", $agent->getComment()); // 'Google CHTML Proxy/1.0' |
---|
65 | * |
---|
66 | * // e.g.) 'DoCoMo/1.0/D505i/c20/TB/W20H10' |
---|
67 | * printf("Status: %s\n", $agent->getStatus()); // 'TB' |
---|
68 | * |
---|
69 | * // only available in eggy/M-stage |
---|
70 | * // e.g.) 'DoCoMo/1.0/eggy/c300/s32/kPHS-K' |
---|
71 | * printf("Bandwidth: %dkbps\n", $agent->getBandwidth()); // 32 |
---|
72 | * </code> |
---|
73 | * |
---|
74 | * @category Networking |
---|
75 | * @package Net_UserAgent_Mobile |
---|
76 | * @author KUBO Atsuhiro <iteman@users.sourceforge.net> |
---|
77 | * @copyright 2003-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> |
---|
78 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
---|
79 | * @version Release: 0.31.0 |
---|
80 | * @link http://www.nttdocomo.co.jp/service/imode/make/content/spec/useragent/index.html |
---|
81 | * @see Net_UserAgent_Mobile_Common |
---|
82 | * @since Class available since Release 0.1 |
---|
83 | */ |
---|
84 | class Net_UserAgent_Mobile_DoCoMo extends Net_UserAgent_Mobile_Common |
---|
85 | { |
---|
86 | |
---|
87 | // {{{ properties |
---|
88 | |
---|
89 | /**#@+ |
---|
90 | * @access public |
---|
91 | */ |
---|
92 | |
---|
93 | /**#@-*/ |
---|
94 | |
---|
95 | /**#@+ |
---|
96 | * @access private |
---|
97 | */ |
---|
98 | |
---|
99 | /** |
---|
100 | * status of the cache (TC, TB, TD, TJ) |
---|
101 | * @var string |
---|
102 | */ |
---|
103 | var $_status; |
---|
104 | |
---|
105 | /** |
---|
106 | * bandwidth like 32 as kilobytes unit |
---|
107 | * @var integer |
---|
108 | */ |
---|
109 | var $_bandwidth; |
---|
110 | |
---|
111 | /** |
---|
112 | * hardware unique serial number |
---|
113 | * @var string |
---|
114 | */ |
---|
115 | var $_serialNumber; |
---|
116 | |
---|
117 | /** |
---|
118 | * whether it's FOMA or not |
---|
119 | * @var boolean |
---|
120 | */ |
---|
121 | var $_isFOMA = false; |
---|
122 | |
---|
123 | /** |
---|
124 | * FOMA Card ID (20 digit alphanumeric) |
---|
125 | * @var string |
---|
126 | */ |
---|
127 | var $_cardID; |
---|
128 | |
---|
129 | /** |
---|
130 | * comment on user agent string like 'Google Proxy' |
---|
131 | * @var string |
---|
132 | */ |
---|
133 | var $_comment; |
---|
134 | |
---|
135 | /** |
---|
136 | * cache size as killobytes unit |
---|
137 | * @var integer |
---|
138 | */ |
---|
139 | var $_cacheSize; |
---|
140 | |
---|
141 | /** |
---|
142 | * width and height of the display |
---|
143 | * @var string |
---|
144 | */ |
---|
145 | var $_displayBytes; |
---|
146 | |
---|
147 | /**#@-*/ |
---|
148 | |
---|
149 | /**#@+ |
---|
150 | * @access public |
---|
151 | */ |
---|
152 | |
---|
153 | // }}} |
---|
154 | // {{{ isDoCoMo() |
---|
155 | |
---|
156 | /** |
---|
157 | * returns true |
---|
158 | * |
---|
159 | * @return boolean |
---|
160 | */ |
---|
161 | function isDoCoMo() |
---|
162 | { |
---|
163 | return true; |
---|
164 | } |
---|
165 | |
---|
166 | // }}} |
---|
167 | // {{{ parse() |
---|
168 | |
---|
169 | /** |
---|
170 | * Parses HTTP_USER_AGENT string. |
---|
171 | * |
---|
172 | * @param string $userAgent User-Agent string |
---|
173 | * @return mixed void, or a PEAR error object on error |
---|
174 | */ |
---|
175 | function parse($userAgent) |
---|
176 | { |
---|
177 | @list($main, $foma_or_comment) = explode(' ', $userAgent, 2); |
---|
178 | |
---|
179 | if ($foma_or_comment |
---|
180 | && preg_match('/^\((.*)\)$/', $foma_or_comment, $matches) |
---|
181 | ) { |
---|
182 | |
---|
183 | // DoCoMo/1.0/P209is (Google CHTML Proxy/1.0) |
---|
184 | $this->_comment = $matches[1]; |
---|
185 | $result = $this->_parseMain($main); |
---|
186 | } elseif ($foma_or_comment) { |
---|
187 | |
---|
188 | // DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789) |
---|
189 | $this->_isFOMA = true; |
---|
190 | list($this->name, $this->version) = explode('/', $main); |
---|
191 | $result = $this->_parseFOMA($foma_or_comment); |
---|
192 | } else { |
---|
193 | |
---|
194 | // DoCoMo/1.0/R692i/c10 |
---|
195 | $result = $this->_parseMain($main); |
---|
196 | } |
---|
197 | |
---|
198 | if (Net_UserAgent_Mobile::isError($result)) { |
---|
199 | return $result; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | // }}} |
---|
204 | // {{{ makeDisplay() |
---|
205 | |
---|
206 | /** |
---|
207 | * create a new {@link Net_UserAgent_Mobile_Display} class instance |
---|
208 | * |
---|
209 | * @return object a newly created {@link Net_UserAgent_Mobile_Display} |
---|
210 | * object |
---|
211 | * @see Net_UserAgent_Mobile_Display |
---|
212 | * @see Net_UserAgent_Mobile_DoCoMoDisplayMap::get() |
---|
213 | */ |
---|
214 | function makeDisplay() |
---|
215 | { |
---|
216 | $display = Net_UserAgent_Mobile_DoCoMoDisplayMap::get($this->getModel()); |
---|
217 | if (!is_null($this->_displayBytes)) { |
---|
218 | list($widthBytes, $heightBytes) = |
---|
219 | explode('*', $this->_displayBytes); |
---|
220 | $display['width_bytes'] = $widthBytes; |
---|
221 | $display['height_bytes'] = $heightBytes; |
---|
222 | } |
---|
223 | return new Net_UserAgent_Mobile_Display($display); |
---|
224 | } |
---|
225 | |
---|
226 | // }}} |
---|
227 | // {{{ getHTMLVersion() |
---|
228 | |
---|
229 | /** |
---|
230 | * returns supported HTML version like '3.0'. retuns null if unknown. |
---|
231 | * |
---|
232 | * @return string |
---|
233 | */ |
---|
234 | function getHTMLVersion() |
---|
235 | { |
---|
236 | static $htmlVersionMap; |
---|
237 | if (!isset($htmlVersionMap)) { |
---|
238 | $htmlVersionMap = array( |
---|
239 | '[DFNP]501i' => '1.0', |
---|
240 | '502i|821i|209i|651|691i|(F|N|P|KO)210i|^F671i$' => '2.0', |
---|
241 | '(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V' => '3.0', |
---|
242 | '504i|251i|^F671iS$|212i|2051|2102V|661i|2701|672i|SO213i|850i' => '4.0', |
---|
243 | 'eggy|P751v' => '3.2', |
---|
244 | '505i|252i|900i|506i|880i|253i|P213i|901i|700i|^(SH|P)851i|701i|881i|^SA800i$|600i|^L601i$|^M702i(S|G)$|^L602i$' => '5.0', |
---|
245 | '902i|702i|851i|882i|^N601i$|^D800iDS$|^P703imyu$|^P704imyu$|^L70[45]i$|^F883i$' => '6.0', |
---|
246 | '903i|703i|904i|704i|883i|801i|^[FD]705i' => '7.0', |
---|
247 | '905i|705i' => '7.1' |
---|
248 | ); |
---|
249 | } |
---|
250 | |
---|
251 | foreach ($htmlVersionMap as $key => $value) { |
---|
252 | if (preg_match("/$key/", $this->_rawModel)) { |
---|
253 | return $value; |
---|
254 | } |
---|
255 | } |
---|
256 | return null; |
---|
257 | } |
---|
258 | |
---|
259 | // }}} |
---|
260 | // {{{ getCacheSize() |
---|
261 | |
---|
262 | /** |
---|
263 | * returns cache size as kilobytes unit. returns 5 if unknown. |
---|
264 | * |
---|
265 | * @return integer |
---|
266 | */ |
---|
267 | function getCacheSize() |
---|
268 | { |
---|
269 | if ($this->_cacheSize) { |
---|
270 | return $this->_cacheSize; |
---|
271 | } |
---|
272 | |
---|
273 | static $defaultCacheSize; |
---|
274 | if (!isset($defaultCacheSize)) { |
---|
275 | $defaultCacheSize = 5; |
---|
276 | } |
---|
277 | return $defaultCacheSize; |
---|
278 | } |
---|
279 | |
---|
280 | // }}} |
---|
281 | // {{{ getSeries() |
---|
282 | |
---|
283 | /** |
---|
284 | * returns series name like '502i'. returns null if unknown. |
---|
285 | * |
---|
286 | * @return string |
---|
287 | */ |
---|
288 | function getSeries() |
---|
289 | { |
---|
290 | if ($this->isFOMA() && preg_match('/(\d{4})/', $this->_rawModel)) { |
---|
291 | return 'FOMA'; |
---|
292 | } |
---|
293 | |
---|
294 | if (preg_match('/(\d{3}i)/', $this->_rawModel, $matches)) { |
---|
295 | return $matches[1]; |
---|
296 | } |
---|
297 | |
---|
298 | if ($this->_rawModel == 'P651ps') { |
---|
299 | return '651'; |
---|
300 | } |
---|
301 | |
---|
302 | return null; |
---|
303 | } |
---|
304 | |
---|
305 | // }}} |
---|
306 | // {{{ getVendor() |
---|
307 | |
---|
308 | /** |
---|
309 | * returns vender code like 'SO' for Sony. returns null if unknown. |
---|
310 | * |
---|
311 | * @return string |
---|
312 | */ |
---|
313 | function getVendor() |
---|
314 | { |
---|
315 | if (preg_match('/([A-Z]+)\d/', $this->_rawModel, $matches)) { |
---|
316 | return $matches[1]; |
---|
317 | } |
---|
318 | |
---|
319 | return null; |
---|
320 | } |
---|
321 | |
---|
322 | // }}} |
---|
323 | // {{{ getStatus() |
---|
324 | |
---|
325 | /** |
---|
326 | * returns status like "TB", "TC", "TD" or "TJ", which means: |
---|
327 | * |
---|
328 | * TB | Browsers |
---|
329 | * TC | Browsers with image off (only Available in HTML 5.0) |
---|
330 | * TD | Fetching JAR |
---|
331 | * TJ | i-Appli |
---|
332 | * |
---|
333 | * @return string |
---|
334 | */ |
---|
335 | function getStatus() |
---|
336 | { |
---|
337 | return $this->_status; |
---|
338 | } |
---|
339 | |
---|
340 | // }}} |
---|
341 | // {{{ getBandwidth() |
---|
342 | |
---|
343 | /** |
---|
344 | * returns bandwidth like 32 as killobytes unit. Only vailable in eggy, |
---|
345 | * returns null otherwise. |
---|
346 | * |
---|
347 | * @return integer |
---|
348 | */ |
---|
349 | function getBandwidth() |
---|
350 | { |
---|
351 | return $this->_bandwidth; |
---|
352 | } |
---|
353 | |
---|
354 | // }}} |
---|
355 | // {{{ getSerialNumber() |
---|
356 | |
---|
357 | /** |
---|
358 | * returns hardware unique serial number (15 digit in FOMA, 11 digit |
---|
359 | * otherwise alphanumeric). Only available with form utn attribute. |
---|
360 | * returns null otherwise. |
---|
361 | * |
---|
362 | * @return string |
---|
363 | */ |
---|
364 | function getSerialNumber() |
---|
365 | { |
---|
366 | return $this->_serialNumber; |
---|
367 | } |
---|
368 | |
---|
369 | // }}} |
---|
370 | // {{{ isFOMA() |
---|
371 | |
---|
372 | /** |
---|
373 | * retuns whether it's FOMA or not |
---|
374 | * |
---|
375 | * @return boolean |
---|
376 | */ |
---|
377 | function isFOMA() |
---|
378 | { |
---|
379 | return $this->_isFOMA; |
---|
380 | } |
---|
381 | |
---|
382 | // }}} |
---|
383 | // {{{ getComment() |
---|
384 | |
---|
385 | /** |
---|
386 | * returns comment on user agent string like 'Google Proxy'. returns null |
---|
387 | * otherwise. |
---|
388 | * |
---|
389 | * @return string |
---|
390 | */ |
---|
391 | function getComment() |
---|
392 | { |
---|
393 | return $this->_comment; |
---|
394 | } |
---|
395 | |
---|
396 | // }}} |
---|
397 | // {{{ getCardID() |
---|
398 | |
---|
399 | /** |
---|
400 | * returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA |
---|
401 | * with <form utn> attribute. returns null otherwise. |
---|
402 | * |
---|
403 | * @return string |
---|
404 | */ |
---|
405 | function getCardID() |
---|
406 | { |
---|
407 | return $this->_cardID; |
---|
408 | } |
---|
409 | |
---|
410 | // }}} |
---|
411 | // {{{ isGPS() |
---|
412 | |
---|
413 | /** |
---|
414 | * @return boolean |
---|
415 | */ |
---|
416 | function isGPS() |
---|
417 | { |
---|
418 | static $gpsModels; |
---|
419 | if (!isset($gpsModels)) { |
---|
420 | $gpsModels = array('F661i', 'F505iGPS'); |
---|
421 | } |
---|
422 | return in_array($this->_rawModel, $gpsModels); |
---|
423 | } |
---|
424 | |
---|
425 | // }}} |
---|
426 | // {{{ getCarrierShortName() |
---|
427 | |
---|
428 | /** |
---|
429 | * returns the short name of the carrier |
---|
430 | * |
---|
431 | * @return string |
---|
432 | */ |
---|
433 | function getCarrierShortName() |
---|
434 | { |
---|
435 | return 'I'; |
---|
436 | } |
---|
437 | |
---|
438 | // }}} |
---|
439 | // {{{ getCarrierLongName() |
---|
440 | |
---|
441 | /** |
---|
442 | * returns the long name of the carrier |
---|
443 | * |
---|
444 | * @return string |
---|
445 | */ |
---|
446 | function getCarrierLongName() |
---|
447 | { |
---|
448 | return 'DoCoMo'; |
---|
449 | } |
---|
450 | |
---|
451 | /**#@-*/ |
---|
452 | |
---|
453 | /**#@+ |
---|
454 | * @access private |
---|
455 | */ |
---|
456 | |
---|
457 | // }}} |
---|
458 | // {{{ _parseMain() |
---|
459 | |
---|
460 | /** |
---|
461 | * parse main part of HTTP_USER_AGENT string (not FOMA) |
---|
462 | * |
---|
463 | * @param string $main main part of HTTP_USER_AGENT string |
---|
464 | * @return mixed void, or a PEAR error object on error |
---|
465 | */ |
---|
466 | function _parseMain($main) |
---|
467 | { |
---|
468 | @list($this->name, $this->version, $this->_rawModel, $cache, $rest) = |
---|
469 | explode('/', $main, 5); |
---|
470 | if ($this->_rawModel == 'SH505i2') { |
---|
471 | $this->_model = 'SH505i'; |
---|
472 | } |
---|
473 | |
---|
474 | if ($cache) { |
---|
475 | if (!preg_match('/^c(\d+)$/', $cache, $matches)) { |
---|
476 | return $this->noMatch(); |
---|
477 | } |
---|
478 | $this->_cacheSize = (integer)$matches[1]; |
---|
479 | } |
---|
480 | |
---|
481 | if ($rest) { |
---|
482 | $rest = explode('/', $rest); |
---|
483 | foreach ($rest as $value) { |
---|
484 | if (preg_match('/^ser(\w{11})$/', $value, $matches)) { |
---|
485 | $this->_serialNumber = $matches[1]; |
---|
486 | continue; |
---|
487 | } |
---|
488 | if (preg_match('/^(T[CDBJ])$/', $value, $matches)) { |
---|
489 | $this->_status = $matches[1]; |
---|
490 | continue; |
---|
491 | } |
---|
492 | if (preg_match('/^s(\d+)$/', $value, $matches)) { |
---|
493 | $this->_bandwidth = (integer)$matches[1]; |
---|
494 | continue; |
---|
495 | } |
---|
496 | if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) { |
---|
497 | $this->_displayBytes = "{$matches[1]}*{$matches[2]}"; |
---|
498 | continue; |
---|
499 | } |
---|
500 | } |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | // }}} |
---|
505 | // {{{ _parseFOMA() |
---|
506 | |
---|
507 | /** |
---|
508 | * parse main part of HTTP_USER_AGENT string (FOMA) |
---|
509 | * |
---|
510 | * @param string $foma main part of HTTP_USER_AGENT string |
---|
511 | * @return mixed void, or a PEAR error object on error |
---|
512 | */ |
---|
513 | function _parseFOMA($foma) |
---|
514 | { |
---|
515 | if (!preg_match('/^([^(\s]+)/', $foma, $matches)) { |
---|
516 | return $this->noMatch(); |
---|
517 | } |
---|
518 | |
---|
519 | $this->_rawModel = $matches[1]; |
---|
520 | if ($this->_rawModel == 'MST_v_SH2101V') { |
---|
521 | $this->_model = 'SH2101V'; |
---|
522 | } |
---|
523 | |
---|
524 | if (preg_match('/^[^(\s]+\s?\((.*?)\)$/', $foma, $matches)) { |
---|
525 | if (preg_match('/^compatible/', $matches[1])) { // The user-agent is DoCoMo compatible. |
---|
526 | $this->_comment = $matches[1]; |
---|
527 | return; |
---|
528 | } |
---|
529 | |
---|
530 | $rest = explode(';', $matches[1]); |
---|
531 | foreach ($rest as $value) { |
---|
532 | if (preg_match('/^c(\d+)$/', $value, $matches)) { |
---|
533 | $this->_cacheSize = (integer)$matches[1]; |
---|
534 | continue; |
---|
535 | } |
---|
536 | if (preg_match('/^ser(\w{15})$/', $value, $matches)) { |
---|
537 | $this->_serialNumber = $matches[1]; |
---|
538 | continue; |
---|
539 | } |
---|
540 | if (preg_match('/^(T[CDBJ])$/', $value, $matches)) { |
---|
541 | $this->_status = $matches[1]; |
---|
542 | continue; |
---|
543 | } |
---|
544 | if (preg_match('/^icc(\w{20})?$/', $value, $matches)) { |
---|
545 | if (count($matches) == 2) { |
---|
546 | $this->_cardID = $matches[1]; |
---|
547 | } |
---|
548 | continue; |
---|
549 | } |
---|
550 | if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) { |
---|
551 | $this->_displayBytes = "{$matches[1]}*{$matches[2]}"; |
---|
552 | continue; |
---|
553 | } |
---|
554 | return $this->noMatch(); |
---|
555 | } |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | /**#@-*/ |
---|
560 | |
---|
561 | // }}} |
---|
562 | } |
---|
563 | |
---|
564 | // }}} |
---|
565 | |
---|
566 | /* |
---|
567 | * Local Variables: |
---|
568 | * mode: php |
---|
569 | * coding: iso-8859-1 |
---|
570 | * tab-width: 4 |
---|
571 | * c-basic-offset: 4 |
---|
572 | * c-hanging-comment-ender-p: nil |
---|
573 | * indent-tabs-mode: nil |
---|
574 | * End: |
---|
575 | */ |
---|