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

Revision 22567, 5.5 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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    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    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        return isset($id) ? $id : false;
82    }
83
84    /**
85     * 携帯端末の機種を表す文字列を取得する。
86     * 携帯端末ではない場合はユーザーエージェントの名前を取得する。(例: 'Mozilla')
87     *
88     * @return string 携帯端末のモデルを表す文字列を返す。
89     */
90    function getModel()
91    {
92        $objAgent =& Net_UserAgent_Mobile::singleton();
93        if (Net_UserAgent_Mobile::isError($objAgent)) {
94            return 'Unknown';
95        } elseif ($objAgent->isNonMobile()) {
96            return $objAgent->getName();
97        } else {
98            return $objAgent->getModel();
99        }
100    }
101
102    /**
103     * EC-CUBE がサポートする携帯端末かどうかを判別する。
104     *
105     * 以下の条件に該当する場合は, false を返す.
106     *
107     * - 携帯端末だと判別されたが, ユーザーエージェントが解析不能な場合
108     * - J-PHONE C4型(パケット非対応)
109     * - EzWeb で WAP2 以外の端末
110     * - DoCoMo 501i, 502i, 209i, 210i, SH821i, N821i, P821i, P651ps, R691i, F671i, SH251i, SH251iS
111     *
112     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
113     */
114    function isSupported()
115    {
116        $objAgent =& Net_UserAgent_Mobile::singleton();
117
118        // 携帯端末だと認識されたが、User-Agent の形式が未知の場合
119        if (Net_UserAgent_Mobile::isError($objAgent)) {
120            GC_Utils_Ex::gfPrintLog($objAgent->toString());
121            return false;
122        }
123
124        if ($objAgent->isDoCoMo()) {
125            $arrUnsupportedSeries = array('501i', '502i', '209i', '210i');
126            $arrUnsupportedModels = array('SH821i', 'N821i', 'P821i ', 'P651ps', 'R691i', 'F671i', 'SH251i', 'SH251iS');
127            return !in_array($objAgent->getSeries(), $arrUnsupportedSeries) && !in_array($objAgent->getModel(), $arrUnsupportedModels);
128        } elseif ($objAgent->isEZweb()) {
129            return $objAgent->isWAP2();
130        } elseif ($objAgent->isVodafone()) {
131            return $objAgent->isPacketCompliant();
132        } else {
133            // 携帯端末ではない場合はサポートしていることにする。
134            return true;
135        }
136    }
137
138    /**
139     * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
140     *
141     * ※一部モジュールで使用。ただし、本メソッドは将来的に削除しますので新規ご利用は控えてください。
142     *
143     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
144     */
145    function isMobile()
146    {
147        $objAgent =& Net_UserAgent_Mobile::singleton();
148        if (Net_UserAgent_Mobile::isError($objAgent)) {
149            return false;
150        } else {
151            return $objAgent->isDoCoMo() || $objAgent->isEZweb() || $objAgent->isVodafone();
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.