1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | require_once(dirname(__FILE__) . '/../module/Net/UserAgent/Mobile.php'); |
---|
24 | |
---|
25 | /** |
---|
26 | * 携帯端末の情報を扱うクラス |
---|
27 | * |
---|
28 | * 対象とする携帯端末は $_SERVER から決定する。 |
---|
29 | * すべてのメソッドはクラスメソッド。 |
---|
30 | */ |
---|
31 | class SC_MobileUserAgent { |
---|
32 | /** |
---|
33 | * 携帯端末のキャリアを表す文字列を取得する。 |
---|
34 | * |
---|
35 | * 文字列は docomo, ezweb, softbank のいずれか。 |
---|
36 | * |
---|
37 | * @return string|false 携帯端末のキャリアを表す文字列を返す。 |
---|
38 | * 携帯端末ではない場合は false を返す。 |
---|
39 | */ |
---|
40 | function getCarrier() { |
---|
41 | $objAgent =& Net_UserAgent_Mobile::singleton(); |
---|
42 | if (Net_UserAgent_Mobile::isError($objAgent)) { |
---|
43 | return false; |
---|
44 | } |
---|
45 | |
---|
46 | switch ($objAgent->getCarrierShortName()) { |
---|
47 | case 'I': |
---|
48 | return 'docomo'; |
---|
49 | case 'E': |
---|
50 | return 'ezweb'; |
---|
51 | case 'V': |
---|
52 | return 'softbank'; |
---|
53 | case 'S': |
---|
54 | return 'softbank'; |
---|
55 | default: |
---|
56 | return false; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * 勝手サイトで利用可能な携帯端末/利用者のIDを取得する。 |
---|
62 | * |
---|
63 | * 各キャリアで使用するIDの種類: |
---|
64 | * + docomo ... UTN |
---|
65 | * + ezweb ... EZ番号 |
---|
66 | * + softbank ... 端末シリアル番号 |
---|
67 | * |
---|
68 | * @return string|false 取得したIDを返す。取得できなかった場合は false を返す。 |
---|
69 | */ |
---|
70 | function getId() { |
---|
71 | $objAgent =& Net_UserAgent_Mobile::singleton(); |
---|
72 | if (Net_UserAgent_Mobile::isError($objAgent)) { |
---|
73 | return false; |
---|
74 | } elseif ($objAgent->isDoCoMo() || $objAgent->isVodafone()) { |
---|
75 | $id = $objAgent->getSerialNumber(); |
---|
76 | } elseif ($objAgent->isEZweb()) { |
---|
77 | $id = @$_SERVER['HTTP_X_UP_SUBNO']; |
---|
78 | } |
---|
79 | return isset($id) ? $id : false; |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * 携帯端末の機種を表す文字列を取得する。 |
---|
84 | * 携帯端末ではない場合はユーザーエージェントの名前を取得する。(例: "Mozilla") |
---|
85 | * |
---|
86 | * @return string 携帯端末のモデルを表す文字列を返す。 |
---|
87 | */ |
---|
88 | function getModel() { |
---|
89 | $objAgent =& Net_UserAgent_Mobile::singleton(); |
---|
90 | if (Net_UserAgent_Mobile::isError($objAgent)) { |
---|
91 | return 'Unknown'; |
---|
92 | } elseif ($objAgent->isNonMobile()) { |
---|
93 | return $objAgent->getName(); |
---|
94 | } else { |
---|
95 | return $objAgent->getModel(); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * EC-CUBE がサポートする携帯キャリアかどうかを判別する。 |
---|
101 | * |
---|
102 | * @return boolean サポートしている場合は true、それ以外の場合は false を返す。 |
---|
103 | */ |
---|
104 | function isMobile() { |
---|
105 | $objAgent =& Net_UserAgent_Mobile::singleton(); |
---|
106 | if (Net_UserAgent_Mobile::isError($objAgent)) { |
---|
107 | return false; |
---|
108 | } else { |
---|
109 | return $objAgent->isDoCoMo() || $objAgent->isEZweb() || $objAgent->isVodafone(); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * EC-CUBE がサポートする携帯キャリアかどうかを判別する。 |
---|
115 | * |
---|
116 | * @return boolean 携帯端末ではない場合は true、それ以外の場合は false を返す。 |
---|
117 | */ |
---|
118 | function isNonMobile() { |
---|
119 | return !SC_MobileUserAgent::isMobile(); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * EC-CUBE がサポートする携帯端末かどうかを判別する。 |
---|
124 | * |
---|
125 | * @return boolean サポートしている場合は true、それ以外の場合は false を返す。 |
---|
126 | */ |
---|
127 | function isSupported() { |
---|
128 | $objAgent =& Net_UserAgent_Mobile::singleton(); |
---|
129 | |
---|
130 | // 携帯端末だと認識されたが、User-Agent の形式が未知の場合 |
---|
131 | if (Net_UserAgent_Mobile::isError($objAgent)) { |
---|
132 | GC_Utils_Ex::gfPrintLog($objAgent->toString()); |
---|
133 | return false; |
---|
134 | } |
---|
135 | |
---|
136 | if ($objAgent->isDoCoMo()) { |
---|
137 | $arrUnsupportedSeries = array('501i', '502i', '209i', '210i'); |
---|
138 | $arrUnsupportedModels = array('SH821i', 'N821i', 'P821i ', 'P651ps', 'R691i', 'F671i', 'SH251i', 'SH251iS'); |
---|
139 | return !in_array($objAgent->getSeries(), $arrUnsupportedSeries) && !in_array($objAgent->getModel(), $arrUnsupportedModels); |
---|
140 | } elseif ($objAgent->isEZweb()) { |
---|
141 | return $objAgent->isWAP2(); |
---|
142 | } elseif ($objAgent->isVodafone()) { |
---|
143 | return $objAgent->isPacketCompliant(); |
---|
144 | } else { |
---|
145 | // 携帯端末ではない場合はサポートしていることにする。 |
---|
146 | return true; |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | ?> |
---|