source: temp/branches/mobile/data/module/Net/UserAgent/Mobile/Vodafone.php @ 11398

Revision 11398, 13.1 KB checked in by rebelt, 20 years ago (diff)

以下のモバイルサイト用ページ・機能を作成いたしました。

  • トップページ
  • 商品閲覧
  • 商品検索
  • セッションIDチェック機能
  • 簡単ログイン補助機能
  • 絵文字変換機能
  • Property svn:eol-style set to native
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4/**
5 * PHP versions 4 and 5
6 *
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to [email protected] so we can mail you a copy immediately.
12 *
13 * @category   Networking
14 * @package    Net_UserAgent_Mobile
15 * @author     KUBO Atsuhiro <[email protected]>
16 * @copyright  2003-2006 KUBO Atsuhiro <[email protected]>
17 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
18 * @version    CVS: $Id: Vodafone.php,v 1.8 2006/11/07 09:25:14 kuboa Exp $
19 * @since      File available since Release 0.1
20 */
21
22require_once dirname(__FILE__) . '/Common.php';
23require_once dirname(__FILE__) . '/Display.php';
24
25/**
26 * Vodafone implementation
27 *
28 * Net_UserAgent_Mobile_Vodafone is a subclass of
29 * {@link Net_UserAgent_Mobile_Common}, which implements Vodafone user agents.
30 *
31 * SYNOPSIS:
32 * <code>
33 * require_once('Net/UserAgent/Mobile.php');
34 *
35 * $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
36 * $agent = &Net_UserAgent_Mobile::factory();
37 *
38 * printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
39 * printf("Version: %s\n", $agent->getVersion()); // 2.0
40 * printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
41 * if ($agent->isPacketCompliant()) {
42 *     print "Packet is compliant.\n"; // false
43 * }
44 *
45 * // only availabe in Java compliant
46 * // e.g.) 'J-PHONE/4.0/J-SH51/SNXXXXXXXXX SH/0001a Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0'
47 * printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
48 * printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
49 * printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
50 *
51 * $info = $agent->getJavaInfo();  // array
52 * foreach ($info as $key => $value) {
53 *     print "$key: $value\n";
54 * }
55 * </code>
56 *
57 * @category   Networking
58 * @package    Net_UserAgent_Mobile
59 * @author     KUBO Atsuhiro <[email protected]>
60 * @copyright  2003-2006 KUBO Atsuhiro <[email protected]>
61 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
62 * @version    Release: @package_version@
63 * @link       http://developers.vodafone.jp/dp/tool_dl/web/useragent.php
64 * @link       http://developers.vodafone.jp/dp/tool_dl/web/position.php
65 * @see        Net_UserAgent_Mobile_Common
66 * @since      Class available since Release 0.1
67 */
68class Net_UserAgent_Mobile_Vodafone extends Net_UserAgent_Mobile_Common
69{
70
71    // {{{ properties
72
73    /**#@+
74     * @access public
75     */
76
77    /**#@-*/
78
79    /**#@+
80     * @access private
81     */
82
83    /**
84     * name of the model like 'J-DN02'
85     * @var string
86     */
87    var $_model = '';
88
89    /**
90     * whether the agent is packet connection complicant or not
91     * @var boolean
92     */
93    var $_packetCompliant = false;
94
95    /**
96     * terminal unique serial number
97     * @var string
98     */
99    var $_serialNumber = null;
100
101    /**
102     * vendor code like 'SH'
103     * @var string
104     */
105    var $_vendor = '';
106
107    /**
108     * vendor version like '0001a'
109     * @var string
110     */
111    var $_vendorVersion = null;
112
113    /**
114     * Java profiles
115     * @var array
116     */
117    var $_javaInfo = array();
118
119    /**
120     * whether the agent is 3G
121     * @var boolean
122     */
123    var $_is3G = true;
124
125    /**
126     * the name of the mobile phone
127     * @var string
128     */
129    var $_msname = '';
130
131    /**#@-*/
132
133    /**#@+
134     * @access public
135     */
136
137    // }}}
138    // {{{ isJPhone()
139
140    /**
141     * returns true
142     *
143     * @return boolean
144     */
145    function isJPhone()
146    {
147        return true;
148    }
149
150    // }}}
151    // {{{ isVodafone()
152
153    /**
154     * returns true
155     *
156     * @return boolean
157     */
158    function isVodafone()
159    {
160        return true;
161    }
162
163    // }}}
164    // {{{ parse()
165
166    /**
167     * parse HTTP_USER_AGENT string
168     *
169     * @return mixed void, or a PEAR error object on error
170     */
171    function parse()
172    {
173        $agent = explode(' ', $this->getUserAgent());
174        preg_match('!^(?:(SoftBank|Vodafone|J-PHONE)/\d\.\d|MOT-)!',
175                   $agent[0], $matches
176                   );
177        if (count($matches) > 1) {
178            $carrier = $matches[1];
179        } else {
180            $carrier = 'Motorola';
181        }
182
183        switch ($carrier) {
184        case 'Vodafone':
185        case 'SoftBank':
186            $result = $this->_parseVodafone($agent);
187            break;
188        case 'J-PHONE':
189            $result = $this->_parseJphone($agent);
190            break;
191        case 'Motorola':
192            $result = $this->_parseMotorola($agent);
193            break;
194        }
195
196        if (Net_UserAgent_Mobile::isError($result)) {
197            return $result;
198        }
199
200        $this->_msname = $this->getHeader('x-jphone-msname');
201    }
202
203    // }}}
204    // {{{ makeDisplay()
205
206    /**
207     * create a new {@link Net_UserAgent_Mobile_Display} class instance
208     *
209     * @return object a newly created {@link Net_UserAgent_Mobile_Display}
210     *     object
211     * @see Net_UserAgent_Mobile_Display
212     */
213    function makeDisplay()
214    {
215        @list($width, $height) =
216            explode('*', $this->getHeader('x-jphone-display'));
217        $color = false;
218        $depth = 0;
219        if ($color_string = $this->getHeader('x-jphone-color')) {
220            preg_match('!^([CG])(\d+)$!', $color_string, $matches);
221            $color = $matches[1] === 'C' ? true : false;
222            $depth = $matches[2];
223        }
224        return new Net_UserAgent_Mobile_Display(array(
225                                                      'width'  => $width,
226                                                      'height' => $height,
227                                                      'depth'  => $depth,
228                                                      'color'  => $color)
229                                                );
230    }
231
232    // }}}
233    // {{{ getModel()
234
235    /**
236     * returns name of the model like 'J-DN02'
237     *
238     * @return string
239     */
240    function getModel()
241    {
242        return $this->_model;
243    }
244
245    // }}}
246    // {{{ isPacketCompliant()
247
248    /**
249     * returns whether the agent is packet connection complicant or not
250     *
251     * @return boolean
252     */
253    function isPacketCompliant()
254    {
255        return $this->_packetCompliant;
256    }
257
258    // }}}
259    // {{{ getSerialNumber()
260
261    /**
262     * return terminal unique serial number. returns null if user forbids to
263     * send his/her serial number.
264     *
265     * @return string
266     */
267    function getSerialNumber()
268    {
269        return $this->_serialNumber;
270    }
271
272    // }}}
273    // {{{ getVendor()
274
275    /**
276     * returns vendor code like 'SH'
277     *
278     * @return string
279     */
280    function getVendor()
281    {
282        return $this->_vendor;
283    }
284
285    // }}}
286    // {{{ getVendorVersion()
287
288    /**
289     * returns vendor version like '0001a'. returns null if unknown.
290     *
291     * @return string
292     */
293    function getVendorVersion()
294    {
295        return $this->_vendorVersion;
296    }
297
298    // }}}
299    // {{{ getJavaInfo()
300
301    /**
302     * returns array of Java profiles
303     *
304     * Array structure is something like:
305     *
306     * - 'Profile'       => 'MIDP-1.0',
307     * - 'Configuration' => 'CLDC-1.0',
308     * - 'Ext-Profile'   => 'JSCL-1.1.0'
309     *
310     * @return array
311     */
312    function getJavaInfo()
313    {
314        return $this->_javaInfo;
315    }
316
317    // }}}
318    // {{{ getCarrierShortName()
319
320    /**
321     * returns the short name of the carrier
322     *
323     * @return string
324     */
325    function getCarrierShortName()
326    {
327        return 'V';
328    }
329
330    // }}}
331    // {{{ getCarrierLongName()
332
333    /**
334     * returns the long name of the carrier
335     *
336     * @return string
337     */
338    function getCarrierLongName()
339    {
340        return 'Vodafone';
341    }
342
343    // }}}
344    // {{{ isTypeC()
345
346    /**
347     * returns true if the type is C
348     *
349     * @return boolean
350     */
351    function isTypeC()
352    {
353        if ($this->_is3G || !preg_match('!^[32]\.!', $this->version)) {
354            return false;
355        }
356
357        return true;
358    }
359
360    // }}}
361    // {{{ isTypeP()
362
363    /**
364     * returns true if the type is P
365     *
366     * @return boolean
367     */
368    function isTypeP()
369    {
370        if ($this->_is3G || !preg_match('!^4\.!', $this->version)) {
371            return false;
372        }
373
374        return true;
375    }
376
377    // }}}
378    // {{{ isTypeW()
379
380    /**
381     * returns true if the type is W
382     *
383     * @return boolean
384     */
385    function isTypeW()
386    {
387        if ($this->_is3G || !preg_match('!^5\.!', $this->version)) {
388            return false;
389        }
390
391        return true;
392    }
393
394    // }}}
395    // {{{ isType3GC()
396
397    /**
398     * returns true if the type is 3GC
399     *
400     * @return boolean
401     */
402    function isType3GC()
403    {
404        return $this->_is3G;
405    }
406
407    // }}}
408    // {{{ getMsname()
409
410    /**
411     * returns the name of the mobile phone
412     *
413     * @return string the name of the mobile phone
414     */
415    function getMsname()
416    {
417        return $this->_msname;
418    }
419
420    /**#@-*/
421
422    /**#@+
423     * @access private
424     */
425
426    // }}}
427    // {{{ _parseVodafone()
428
429    /**
430     * parse HTTP_USER_AGENT string for the Vodafone 3G aegnt
431     *
432     * @param array $agent parts of the User-Agent string
433     * @return mixed void, or a PEAR error object on error
434     */
435    function _parseVodafone(&$agent)
436    {
437        $count = count($agent);
438        $this->_packetCompliant = true;
439
440        // Vodafone/1.0/V702NK/NKJ001 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
441        // Vodafone/1.0/V702NK/NKJ001/SN123456789012345 Series60/2.6 Nokia6630/2.39.148 Profile/MIDP-2.0 Configuration/CLDC-1.1
442        // Vodafone/1.0/V802SE/SEJ001/SN123456789012345 Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
443        @list($this->name, $this->version, $this->_model, $modelVersion,
444              $serialNumber) = explode('/', $agent[0]);
445        if ($serialNumber) {
446            if ($serialNumber) {
447                if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
448                    return $this->noMatch();
449                }
450                $this->_serialNumber = $matches[1];
451            }
452        }
453
454        if (!preg_match('!^([a-z]+)([a-z]\d{2,3})$!i', $modelVersion, $matches)) {
455            return $this->noMatch();
456        }
457
458        $this->_vendor = $matches[1];
459        $this->_vendorVersion = $matches[2];
460
461        for ($i = 2; $i < $count; ++$i) {
462            list($key, $value) = explode('/', $agent[$i]);
463            $this->_javaInfo[$key] = $value;
464        }
465    }
466
467    // }}}
468    // {{{ _parseJphone()
469
470    /**
471     * parse HTTP_USER_AGENT string for the ancient agent
472     *
473     * @param array $agent parts of the User-Agent string
474     * @return mixed void, or a PEAR error object on error
475     */
476    function _parseJphone(&$agent)
477    {
478        $count = count($agent);
479        $this->_is3G = false;
480
481        if ($count > 1) {
482
483            // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
484            $this->_packetCompliant = true;
485            @list($this->name, $this->version, $this->_model,
486                  $serialNumber) = explode('/', $agent[0]);
487            if ($serialNumber) {
488                if (!preg_match('!^SN(.+)!', $serialNumber, $matches)) {
489                    return $this->noMatch();
490                }
491                $this->_serialNumber = $matches[1];
492            }
493            list($this->_vendor, $this->_vendorVersion) =
494                explode('/', $agent[1]);
495            for ($i = 2; $i < $count; ++$i) {
496                list($key, $value) = explode('/', $agent[$i]);
497                $this->_javaInfo[$key] = $value;
498            }
499        } else {
500
501            // J-PHONE/2.0/J-DN02
502            @list($this->name, $this->version, $model) =
503                explode('/', $agent[0]);
504            $this->_model  = (string)$model;
505            if ($this->_model) {
506                if (preg_match('!V\d+([A-Z]+)!', $this->_model, $matches)) {
507                    $this->_vendor = $matches[1];
508                } elseif (preg_match('!J-([A-Z]+)!', $this->_model, $matches)) {
509                    $this->_vendor = $matches[1];
510                }
511            }
512        }
513    }
514
515    // }}}
516    // {{{ _parseMotorola()
517
518    /**
519     * parse HTTP_USER_AGENT string for the Motorola 3G aegnt
520     *
521     * @param array $agent parts of the User-Agent string
522     * @return mixed void, or a PEAR error object on error
523     */
524    function _parseMotorola(&$agent)
525    {
526        $count = count($agent);
527        $this->_packetCompliant = true;
528        $this->_vendor = 'MOT';
529
530        // MOT-V980/80.2F.2E. MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1
531        list($name, $this->_vendorVersion) = explode('/', $agent[0]);
532        $this->_model = substr(strrchr($name, '-'), 1);
533
534        for ($i = 2; $i < $count; ++$i) {
535            list($key, $value) = explode('/', $agent[$i]);
536            $this->_javaInfo[$key] = $value;
537        }
538    }
539
540    /**#@-*/
541
542    // }}}
543}
544
545// }}}
546
547/*
548 * Local Variables:
549 * mode: php
550 * coding: iso-8859-1
551 * tab-width: 4
552 * c-basic-offset: 4
553 * c-hanging-comment-ender-p: nil
554 * indent-tabs-mode: nil
555 * End:
556 */
557?>
Note: See TracBrowser for help on using the repository browser.