source: branches/version-2_5-dev/data/module/Net/UserAgent/Mobile/EZweb.php @ 20116

Revision 20116, 8.5 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4/**
5 * PHP versions 4 and 5
6 *
7 * Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>,
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
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.
18 *
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.
30 *
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$
37 * @link       http://www.au.kddi.com/ezfactory/tec/spec/4_4.html
38 * @link       http://www.au.kddi.com/ezfactory/tec/spec/new_win/ezkishu.html
39 * @since      File available since Release 0.1.0
40 */
41
42require_once dirname(__FILE__) . '/Common.php';
43require_once dirname(__FILE__) . '/Display.php';
44
45// {{{ Net_UserAgent_Mobile_EZweb
46
47/**
48 * EZweb implementation
49 *
50 * Net_UserAgent_Mobile_EZweb is a subclass of {@link Net_UserAgent_Mobile_Common},
51 * which implements EZweb (WAP1.0/2.0) user agents.
52 *
53 * SYNOPSIS:
54 * <code>
55 * require_once 'Net/UserAgent/Mobile.php';
56 *
57 * $_SERVER['HTTP_USER_AGENT'] = 'UP.Browser/3.01-HI02 UP.Link/3.2.1.2';
58 * $agent = &Net_UserAgent_Mobile::factory();
59 *
60 * printf("Name: %s\n", $agent->getName()); // 'UP.Browser'
61 * printf("Version: %s\n", $agent->getVersion()); // 3.01
62 * printf("DeviceID: %s\n", $agent->getDeviceID()); // 'HI02'
63 * printf("Server: %s\n", $agent->getServer()); // 'UP.Link/3.2.1.2'
64 *
65 * e.g.) 'UP.Browser/3.01-HI02 UP.Link/3.2.1.2 (Google WAP Proxy/1.0)'
66 * printf("Comment: %s\n", $agent->getComment()); // 'Google WAP Proxy/1.0'
67 *
68 * e.g.) 'KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1'
69 * if ($agent->isXHTMLCompliant()) {
70 *     print "XHTML compliant!\n"; // true
71 * }
72 * </code>
73 *
74 * @category   Networking
75 * @package    Net_UserAgent_Mobile
76 * @author     KUBO Atsuhiro <kubo@iteman.jp>
77 * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
78 * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
79 * @version    Release: 1.0.0
80 * @link       http://www.au.kddi.com/ezfactory/tec/spec/4_4.html
81 * @link       http://www.au.kddi.com/ezfactory/tec/spec/new_win/ezkishu.html
82 * @since      Class available since Release 0.1.0
83 */
84class Net_UserAgent_Mobile_EZweb extends Net_UserAgent_Mobile_Common
85{
86
87    // {{{ properties
88
89    /**#@+
90     * @access public
91     */
92
93    /**#@-*/
94
95    /**#@+
96     * @access private
97     */
98
99    /**
100     * server string like 'UP.Link/3.2.1.2'
101     * @var string
102     */
103    var $_serverName = '';
104
105    /**
106     * comment like 'Google WAP Proxy/1.0'
107     * @var string
108     */
109    var $_comment = null;
110
111    /**
112     * whether it's XHTML compliant or not
113     * @var boolean
114     */
115    var $_xhtmlCompliant = false;
116
117    /**#@-*/
118
119    /**#@+
120     * @access public
121     */
122
123    // }}}
124    // {{{ isEZweb()
125
126    /**
127     * returns true
128     *
129     * @return boolean
130     */
131    function isEZweb()
132    {
133        return true;
134    }
135
136    // }}}
137    // {{{ isTUKa()
138
139    /**
140     * returns true if the agent is TU-Ka
141     *
142     * @return boolean
143     */
144    function isTUKa()
145    {
146        $tuka = substr($this->_rawModel, 2, 1);
147        if ($this->isWAP2()) {
148            if ($tuka == 'U') {
149                return true;
150            }
151        } else {
152            if ($tuka == 'T') {
153                return true;
154            }
155        }
156       
157        return false;
158    }
159
160    // }}}
161    // {{{ parse()
162
163    /**
164     * Parses HTTP_USER_AGENT string.
165     *
166     * @param string $userAgent User-Agent string
167     */
168    function parse($userAgent)
169    {
170        if (preg_match('/^KDDI-(.*)/', $userAgent, $matches)) {
171
172            // KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1
173            $this->_xhtmlCompliant = true;
174            @list($this->_rawModel, $browser, $opt, $this->_serverName) =
175                explode(' ', $matches[1], 4);
176            @list($this->name, $version) = explode('/', $browser);
177            $this->version = "$version $opt";
178        } else {
179
180            // UP.Browser/3.01-HI01 UP.Link/3.4.5.2
181            @list($browser, $this->_serverName, $comment) =
182                explode(' ', $userAgent, 3);
183            @list($this->name, $software) = explode('/', $browser);
184            @list($this->version, $this->_rawModel) = explode('-', $software);
185            if ($comment) {
186                $this->_comment = preg_replace('/^\((.*)\)$/', '$1', $comment);
187            }
188        }
189    }
190
191    // }}}
192    // {{{ makeDisplay()
193
194    /**
195     * create a new {@link Net_UserAgent_Mobile_Display} class instance
196     *
197     * @return Net_UserAgent_Mobile_Display
198     */
199    function makeDisplay()
200    {
201        @list($width, $height) =
202            explode(',', $this->getHeader('X-UP-DEVCAP-SCREENPIXELS'));
203        $screenDepth = explode(',', $this->getHeader('X-UP-DEVCAP-SCREENDEPTH'));
204        $depth = $screenDepth[0] ? pow(2, (integer)$screenDepth[0]) : 0;
205        $color = $this->getHeader('X-UP-DEVCAP-ISCOLOR') === '1' ? true : false;
206        return new Net_UserAgent_Mobile_Display(array('width'  => $width,
207                                                      'height' => $height,
208                                                      'color'  => $color,
209                                                      'depth'  => $depth)
210                                                );
211    }
212
213    // }}}
214    // {{{ getDeviceID()
215
216    /**
217     * Returns the device ID of the user agent.
218     *
219     * @return string
220     */
221    function getDeviceID()
222    {
223        return $this->_rawModel;
224    }
225
226    // }}}
227    // {{{ getServer()
228
229    /**
230     * returns server string like 'UP.Link/3.2.1.2'
231     *
232     * @return string
233     */
234    function getServer()
235    {
236        return $this->_serverName;
237    }
238
239    // }}}
240    // {{{ getComment()
241
242    /**
243     * returns comment like 'Google WAP Proxy/1.0'. returns null if nothinng.
244     *
245     * @return boolean
246     */
247    function getComment()
248    {
249        return $this->_comment;
250    }
251
252    // }}}
253    // {{{ isXHTMLCompliant()
254
255    /**
256     * returns whether it's XHTML compliant or not
257     *
258     * @return boolean
259     */
260    function isXHTMLCompliant()
261    {
262        return $this->_xhtmlCompliant;
263    }
264
265    // }}}
266    // {{{ getCarrierShortName()
267
268    /**
269     * returns the short name of the carrier
270     *
271     * @return string
272     */
273    function getCarrierShortName()
274    {
275        return 'E';
276    }
277
278    // }}}
279    // {{{ getCarrierLongName()
280
281    /**
282     * returns the long name of the carrier
283     *
284     * @return string
285     */
286    function getCarrierLongName()
287    {
288        return 'EZweb';
289    }
290
291    // }}}
292    // {{{ isWIN()
293
294    /**
295     * Returns whether the agent is CDMA 1X WIN or not.
296     *
297     * @return boolean
298     */
299    function isWIN()
300    {
301        return substr($this->_rawModel, 2, 1) == 3 ? true : false;
302    }
303
304    // }}}
305    // {{{ getUID()
306
307    /**
308     * Gets the UID of a subscriber.
309     *
310     * @return string
311     * @since Method available since Release 1.0.0RC1
312     */
313    function getUID()
314    {
315        if (array_key_exists('HTTP_X_UP_SUBNO', $_SERVER)) {
316            return $_SERVER['HTTP_X_UP_SUBNO'];
317        }
318    }
319
320    /**#@-*/
321
322    /**#@+
323     * @access private
324     */
325
326    /**#@-*/
327
328    // }}}
329}
330
331// }}}
332
333/*
334 * Local Variables:
335 * mode: php
336 * coding: iso-8859-1
337 * tab-width: 4
338 * c-basic-offset: 4
339 * c-hanging-comment-ender-p: nil
340 * indent-tabs-mode: nil
341 * End:
342 */
Note: See TracBrowser for help on using the repository browser.