source: branches/version-2_13-dev/data/class/SC_MobileUserAgent.php @ 23124

Revision 23124, 5.5 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
24/**
25 * 携帯端末の情報を扱うクラス
26 *
27 * 対象とする携帯端末は $_SERVER から決定する。
28 * 全てのメソッドはクラスメソッド。
29 */
30class SC_MobileUserAgent
31{
32    /**
33     * 携帯端末のキャリアを表す文字列を取得する。
34     *
35     * 文字列は docomo, ezweb, softbank のいずれか。
36     *
37     * @return string|false 携帯端末のキャリアを表す文字列を返す。
38     *                      携帯端末ではない場合は false を返す。
39     */
40    public function getCarrier()
41    {
42        $objAgent =& Net_UserAgent_Mobile::singleton();
43        if (Net_UserAgent_Mobile::isError($objAgent)) {
44            return false;
45        }
46
47        switch ($objAgent->getCarrierShortName()) {
48            case 'I':
49                return 'docomo';
50            case 'E':
51                return 'ezweb';
52            case 'V':
53                return 'softbank';
54            case 'S':
55                return 'softbank';
56            default:
57                return false;
58        }
59    }
60
61    /**
62     * 勝手サイトで利用可能な携帯端末/利用者のIDを取得する。
63     *
64     * 各キャリアで使用するIDの種類:
65     * + docomo   ... UTN
66     * + ezweb    ... EZ番号
67     * + softbank ... 端末シリアル番号
68     *
69     * @return string|false 取得したIDを返す。取得できなかった場合は false を返す。
70     */
71    public function getId()
72    {
73        $objAgent =& Net_UserAgent_Mobile::singleton();
74        if (Net_UserAgent_Mobile::isError($objAgent)) {
75            return false;
76        } elseif ($objAgent->isDoCoMo() || $objAgent->isVodafone()) {
77            $id = $objAgent->getSerialNumber();
78        } elseif ($objAgent->isEZweb()) {
79            $id = @$_SERVER['HTTP_X_UP_SUBNO'];
80        }
81
82        return isset($id) ? $id : false;
83    }
84
85    /**
86     * 携帯端末の機種を表す文字列を取得する。
87     * 携帯端末ではない場合はユーザーエージェントの名前を取得する。(例: 'Mozilla')
88     *
89     * @return string 携帯端末のモデルを表す文字列を返す。
90     */
91    public function getModel()
92    {
93        $objAgent =& Net_UserAgent_Mobile::singleton();
94        if (Net_UserAgent_Mobile::isError($objAgent)) {
95            return 'Unknown';
96        } elseif ($objAgent->isNonMobile()) {
97            return $objAgent->getName();
98        } else {
99            return $objAgent->getModel();
100        }
101    }
102
103    /**
104     * EC-CUBE がサポートする携帯端末かどうかを判別する。
105     *
106     * 以下の条件に該当する場合は, false を返す.
107     *
108     * - 携帯端末だと判別されたが, ユーザーエージェントが解析不能な場合
109     * - J-PHONE C4型(パケット非対応)
110     * - EzWeb で WAP2 以外の端末
111     * - DoCoMo 501i, 502i, 209i, 210i, SH821i, N821i, P821i, P651ps, R691i, F671i, SH251i, SH251iS
112     *
113     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
114     */
115    public function isSupported()
116    {
117        $objAgent =& Net_UserAgent_Mobile::singleton();
118
119        // 携帯端末だと認識されたが、User-Agent の形式が未知の場合
120        if (Net_UserAgent_Mobile::isError($objAgent)) {
121            GC_Utils_Ex::gfPrintLog($objAgent->toString());
122
123            return false;
124        }
125
126        if ($objAgent->isDoCoMo()) {
127            $arrUnsupportedSeries = array('501i', '502i', '209i', '210i');
128            $arrUnsupportedModels = array('SH821i', 'N821i', 'P821i ', 'P651ps', 'R691i', 'F671i', 'SH251i', 'SH251iS');
129
130            return !in_array($objAgent->getSeries(), $arrUnsupportedSeries) && !in_array($objAgent->getModel(), $arrUnsupportedModels);
131        } elseif ($objAgent->isEZweb()) {
132            return $objAgent->isWAP2();
133        } elseif ($objAgent->isVodafone()) {
134            return $objAgent->isPacketCompliant();
135        } else {
136            // 携帯端末ではない場合はサポートしていることにする。
137            return true;
138        }
139    }
140
141    /**
142     * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
143     *
144     * ※一部モジュールで使用。ただし、本メソッドは将来的に削除しますので新規ご利用は控えてください。
145     *
146     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
147     */
148    public function isMobile()
149    {
150        $objAgent =& Net_UserAgent_Mobile::singleton();
151        if (Net_UserAgent_Mobile::isError($objAgent)) {
152            return false;
153        } else {
154            return $objAgent->isDoCoMo() || $objAgent->isEZweb() || $objAgent->isVodafone();
155        }
156    }
157}
Note: See TracBrowser for help on using the repository browser.