source: branches/feature-module-update/data/class/GC_MobileUserAgent.php @ 15080

Revision 15080, 4.1 KB checked in by nanasess, 17 years ago (diff)

svn properties 設定

  • svn:mime-type - application/x-httpd-php; charset=UTF-8
  • svn:keywords - Id
  • Property svn:keywords set to Id
  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1<?php
2/**
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 */
9require_once(dirname(__FILE__) . '/../module/Net/UserAgent/Mobile.php');
10
11/**
12 * 携帯端末の情報を扱うクラス
13 *
14 * 対象とする携帯端末は $_SERVER から決定する。
15 * すべてのメソッドはクラスメソッド。
16 */
17class GC_MobileUserAgent {
18    /**
19     * 携帯端末のキャリアを表す文字列を取得する。
20     *
21     * 文字列は docomo, ezweb, softbank のいずれか。
22     *
23     * @return string|false 携帯端末のキャリアを表す文字列を返す。
24     *                      携帯端末ではない場合は false を返す。
25     */
26    function getCarrier() {
27        $objAgent =& Net_UserAgent_Mobile::singleton();
28        if (Net_UserAgent_Mobile::isError($objAgent)) {
29            return false;
30        }
31
32        switch ($objAgent->getCarrierShortName()) {
33        case 'I':
34            return 'docomo';
35        case 'E':
36            return 'ezweb';
37        case 'V':
38            return 'softbank';
39        default:
40            return false;
41        }
42    }
43
44    /**
45     * 勝手サイトで利用可能な携帯端末/利用者のIDを取得する。
46     *
47     * 各キャリアで使用するIDの種類:
48     * + docomo   ... UTN
49     * + ezweb    ... EZ番号
50     * + softbank ... 端末シリアル番号
51     *
52     * @return string|false 取得したIDを返す。取得できなかった場合は false を返す。
53     */
54    function getId() {
55        $objAgent =& Net_UserAgent_Mobile::singleton();
56        if (Net_UserAgent_Mobile::isError($objAgent)) {
57            return false;
58        } elseif ($objAgent->isDoCoMo() || $objAgent->isVodafone()) {
59            $id = $objAgent->getSerialNumber();
60        } elseif ($objAgent->isEZweb()) {
61            $id = @$_SERVER['HTTP_X_UP_SUBNO'];
62        }
63        return isset($id) ? $id : false;
64    }
65
66    /**
67     * 携帯端末の機種を表す文字列を取得する。
68     * 携帯端末ではない場合はユーザーエージェントの名前を取得する。(例: "Mozilla")
69     *
70     * @return string 携帯端末のモデルを表す文字列を返す。
71     */
72    function getModel() {
73        $objAgent =& Net_UserAgent_Mobile::singleton();
74        if (Net_UserAgent_Mobile::isError($objAgent)) {
75            return 'Unknown';
76        } elseif ($objAgent->isNonMobile()) {
77            return $objAgent->getName();
78        } else {
79            return $objAgent->getModel();
80        }
81    }
82
83    /**
84     * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
85     *
86     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
87     */
88    function isMobile() {
89        $objAgent =& Net_UserAgent_Mobile::singleton();
90        if (Net_UserAgent_Mobile::isError($objAgent)) {
91            return false;
92        } else {
93            return $objAgent->isDoCoMo() || $objAgent->isEZweb() || $objAgent->isVodafone();
94        }
95    }
96
97    /**
98     * EC-CUBE がサポートする携帯キャリアかどうかを判別する。
99     *
100     * @return boolean 携帯端末ではない場合は true、それ以外の場合は false を返す。
101     */
102    function isNonMobile() {
103        return !GC_MobileUserAgent::isMobile();
104    }
105
106    /**
107     * EC-CUBE がサポートする携帯端末かどうかを判別する。
108     *
109     * @return boolean サポートしている場合は true、それ以外の場合は false を返す。
110     */
111    function isSupported() {
112        $objAgent =& Net_UserAgent_Mobile::singleton();
113
114        // 携帯端末だと認識されたが、User-Agent の形式が未知の場合
115        if (Net_UserAgent_Mobile::isError($objAgent)) {
116            gfPrintLog($objAgent->toString());
117            return false;
118        }
119
120        if ($objAgent->isDoCoMo()) {
121            $arrUnsupportedSeries = array('501i', '502i', '209i', '210i');
122            $arrUnsupportedModels = array('SH821i', 'N821i', 'P821i ', 'P651ps', 'R691i', 'F671i', 'SH251i', 'SH251iS');
123            return !in_array($objAgent->getSeries(), $arrUnsupportedSeries) && !in_array($objAgent->getModel(), $arrUnsupportedModels);
124        } elseif ($objAgent->isEZweb()) {
125            return $objAgent->isWAP2();
126        } elseif ($objAgent->isVodafone()) {
127            return $objAgent->isPacketCompliant();
128        } else {
129            // 携帯端末ではない場合はサポートしていることにする。
130            return true;
131        }
132    }
133}
134?>
Note: See TracBrowser for help on using the repository browser.