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: SoftBank.php 2043 2009-07-03 09:36:18Z fishbone $
37 * @link http://creation.mb.softbank.jp/
38 * @since File available since Release 0.20.0
40 * @modified-for adjust for magic3 framework
41 * @modified-by naoki hirata(naoki@aplo.co.jp)
42 * @modified-date 2009.7.3
45 //require_once 'Net/UserAgent/Mobile/Common.php';
46 //require_once 'Net/UserAgent/Mobile/Display.php';
47 //require_once 'Net/UserAgent/Mobile.php';
48 require_once dirname(__FILE__) . '/Common.php'; // modified by naoki.
49 require_once dirname(__FILE__) . '/Display.php'; // modified by naoki.
51 // {{{ Net_UserAgent_Mobile_SoftBank
54 * SoftBank implementation
56 * Net_UserAgent_Mobile_SoftBank is a subclass of {@link Net_UserAgent_Mobile_Common},
57 * which implements SoftBank user agents.
61 * require_once 'Net/UserAgent/Mobile.php';
63 * $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
64 * $agent = &Net_UserAgent_Mobile::factory();
66 * printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
67 * printf("Version: %s\n", $agent->getVersion()); // 2.0
68 * printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
69 * if ($agent->isPacketCompliant()) {
70 * print "Packet is compliant.\n"; // false
73 * // only availabe in Java compliant
74 * // 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'
75 * printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
76 * printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
77 * printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
79 * $info = $agent->getJavaInfo(); // array
80 * foreach ($info as $key => $value) {
81 * print "$key: $value\n";
85 * @category Networking
86 * @package Net_UserAgent_Mobile
87 * @author KUBO Atsuhiro <kubo@iteman.jp>
88 * @copyright 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
89 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
90 * @version Release: 1.0.0
91 * @link http://creation.mb.softbank.jp/
92 * @since Class available since Release 0.20.0
94 class Net_UserAgent_Mobile_SoftBank extends Net_UserAgent_Mobile_Common
110 * whether the agent is packet connection complicant or not
113 var $_packetCompliant = false;
116 * terminal unique serial number
122 * vendor code like 'SH'
128 * vendor version like '0001a'
137 var $_javaInfo = array();
140 * whether the agent is 3G
146 * the name of the mobile phone
167 return $this->isSoftBank();
178 function isVodafone()
180 return $this->isSoftBank();
187 * Parses HTTP_USER_AGENT string.
189 * @param string $userAgent User-Agent string
190 * @throws Net_UserAgent_Mobile_Error
192 function parse($userAgent)
194 $agent = explode(' ', $userAgent);
195 preg_match('!^(?:(SoftBank|Semulator|Vodafone|Vemulator|J-PHONE|J-EMULATOR)/\d\.\d|MOT-|MOTEMULATOR)!',
198 if (count($matches) > 1) {
199 $carrier = $matches[1];
201 $carrier = 'Motorola';
209 $result = $this->_parseVodafone($agent);
213 $result = $this->_parseJphone($agent);
217 $result = $this->_parseMotorola($agent);
221 if (Net_UserAgent_Mobile::isError($result)) {
225 $this->_msname = $this->getHeader('X-JPHONE-MSNAME');
232 * create a new {@link Net_UserAgent_Mobile_Display} class instance
234 * @return Net_UserAgent_Mobile_Display
236 function makeDisplay()
238 @list($width, $height) = explode('*', $this->getHeader('X-JPHONE-DISPLAY'));
241 if ($color_string = $this->getHeader('X-JPHONE-COLOR')) {
242 preg_match('!^([CG])(\d+)$!', $color_string, $matches);
243 $color = $matches[1] === 'C' ? true : false;
244 $depth = $matches[2];
247 return new Net_UserAgent_Mobile_Display(array('width' => $width,
255 // {{{ isPacketCompliant()
258 * returns whether the agent is packet connection complicant or not
262 function isPacketCompliant()
264 return $this->_packetCompliant;
268 // {{{ getSerialNumber()
271 * return terminal unique serial number. returns null if user forbids to send
272 * his/her serial number.
276 function getSerialNumber()
278 return $this->_serialNumber;
285 * returns vendor code like 'SH'
291 return $this->_vendor;
295 // {{{ getVendorVersion()
298 * returns vendor version like '0001a'. returns null if unknown.
302 function getVendorVersion()
304 return $this->_vendorVersion;
311 * returns array of Java profiles
313 * Array structure is something like:
315 * - 'Profile' => 'MIDP-1.0',
316 * - 'Configuration' => 'CLDC-1.0',
317 * - 'Ext-Profile' => 'JSCL-1.1.0'
321 function getJavaInfo()
323 return $this->_javaInfo;
327 // {{{ getCarrierShortName()
330 * returns the short name of the carrier
334 function getCarrierShortName()
340 // {{{ getCarrierLongName()
343 * returns the long name of the carrier
347 function getCarrierLongName()
356 * returns true if the type is C
362 if ($this->_is3G || !preg_match('!^[32]\.!', $this->version)) {
373 * returns true if the type is P
379 if ($this->_is3G || !preg_match('!^4\.!', $this->version)) {
390 * returns true if the type is W
396 if ($this->_is3G || !preg_match('!^5\.!', $this->version)) {
407 * returns true if the type is 3GC
420 * returns the name of the mobile phone
422 * @return string the name of the mobile phone
426 return $this->_msname;
433 * returns true if the agent is SoftBank.
437 function isSoftBank()
446 * Gets the UID of a subscriber.
449 * @since Method available since Release 1.0.0RC1
453 if (array_key_exists('HTTP_X_JPHONE_UID', $_SERVER)) {
454 return $_SERVER['HTTP_X_JPHONE_UID'];
465 // {{{ _parseVodafone()
468 * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
470 * @param array $agent parts of the User-Agent string
471 * @throws Net_UserAgent_Mobile_Error
473 function _parseVodafone($agent)
475 $this->_packetCompliant = true;
477 // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
478 // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
479 // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
480 @list($this->name, $this->version, $this->_rawModel, $modelVersion,
481 $serialNumber) = explode('/', $agent[0]);
483 if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
484 return $this->noMatch();
487 $this->_serialNumber = $matches[1];
490 if (!preg_match('!^([a-z]+)((?:[a-z]|\d){4})$!i', $modelVersion, $matches)) {
491 return $this->noMatch();
494 $this->_vendor = $matches[1];
495 $this->_vendorVersion = $matches[2];
497 for ($i = 2, $count = count($agent); $i < $count; ++$i) {
498 @list($key, $value) = explode('/', $agent[$i]);
499 $this->_javaInfo[$key] = $value;
504 // {{{ _parseJphone()
507 * parse HTTP_USER_AGENT string for the ancient agent
509 * @param array $agent parts of the User-Agent string
510 * @throws Net_UserAgent_Mobile_Error
512 function _parseJphone($agent)
514 $count = count($agent);
515 $this->_is3G = false;
519 // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
520 $this->_packetCompliant = true;
521 @list($this->name, $this->version, $this->_rawModel, $serialNumber) =
522 explode('/', $agent[0]);
524 if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
525 return $this->noMatch();
528 $this->_serialNumber = $matches[1];
531 @list($this->_vendor, $this->_vendorVersion) = explode('/', $agent[1]);
532 for ($i = 2; $i < $count; ++$i) {
533 @list($key, $value) = explode('/', $agent[$i]);
534 $this->_javaInfo[$key] = $value;
538 // J-PHONE/2.0/J-DN02
539 @list($this->name, $this->version, $this->_rawModel, $serialNumber) =
540 explode('/', $agent[0]);
542 if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
543 return $this->noMatch();
546 $this->_serialNumber = $matches[1];
549 if ($this->_rawModel) {
550 if (preg_match('!V\d+([A-Z]+)!', $this->_rawModel, $matches)) {
551 $this->_vendor = $matches[1];
552 } elseif (preg_match('!J-([A-Z]+)!', $this->_rawModel, $matches)) {
553 $this->_vendor = $matches[1];
560 // {{{ _parseMotorola()
563 * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
565 * @param array $agent parts of the User-Agent string
567 function _parseMotorola($agent)
569 $this->_packetCompliant = true;
570 $this->_vendor = 'MOT';
572 // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
573 @list($this->_rawModel, $this->_vendorVersion) = explode('/', $agent[0]);
574 $this->_model = substr(strrchr($this->_rawModel, '-'), 1);
576 for ($i = 2, $count = count($agent); $i < $count; ++$i) {
577 @list($key, $value) = explode('/', $agent[$i]);
578 $this->_javaInfo[$key] = $value;
595 * c-hanging-comment-ender-p: nil
596 * indent-tabs-mode: nil