Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 299 lines (268 sloc) 7.921 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: KUBO Atsuhiro <kubo@isite.co.jp> |
// +----------------------------------------------------------------------+
//
// $Id$
//
// SYNOPSIS:
// require_once('Net/UserAgent/Mobile.php');
//
// $_SERVER['HTTP_USER_AGENT'] = 'J-PHONE/2.0/J-DN02';
// $agent = &Net_UserAgent_Mobile::factory();
//
// printf("Name: %s\n", $agent->getName()); // 'J-PHONE'
// printf("Version: %s\n", $agent->getVersion()); // 2.0
// printf("Model: %s\n", $agent->getModel()); // 'J-DN02'
// if ($agent->isPacketCompliant()) {
// print "Packet is compliant.\n"; // FALSE
// }
//
// // only availabe in Java compliant
// // 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'
// printf("Serial: %s\n", $agent->getSerialNumber()); // XXXXXXXXX
// printf("Vendor: %s\n", $agent->getVendor()); // 'SH'
// printf("Vendor Version: %s\n", $agent->getVendorVersion()); // '0001a'
//
// $info = $agent->getJavaInfo(); // array
// foreach ($info as $key => $value) {
// print "$key: $value\n";
// }
//

require_once('Net/UserAgent/Mobile/Common.php');
require_once('Net/UserAgent/Mobile/Display.php');

/**
* J-PHONE implementation
*
* Net_UserAgent_Mobile_JPhone is a subclass of Net_UserAgent_Mobile, which
* implements J-PHONE user agents.
*
* @package Net_UserAgent_Mobile
* @version $Revision$
* @author KUBO Atsuhiro <kubo@isite.co.jp>
* @access public
* @see Net_UserAgent_Mobile_Common()
* @see http://www.dp.j-phone.com/jsky/user.html
* @see http://www.dp.j-phone.com/jsky/position.html
*/
class Net_UserAgent_Mobile_JPhone extends Net_UserAgent_Mobile_Common
{

    // {{{ properties

    /**
* name of the model like 'J-DN02'
* @var string
* @access private
*/
    var $_model = '';

    /**
* whether the agent is packet connection complicant or not
* @var boolean
* @access private
*/
    var $_packet_compliant = FALSE;

    /**
* terminal unique serial number
* @var string
* @access private
*/
    var $_serial_number = NULL;

    /**
* vendor code like 'SH'
* @var string
* @access private
*/
    var $_vendor = '';

    /**
* vendor version like '0001a'
* @var string
* @access private
*/
    var $_vendor_version = NULL;

    /**
*
* @var array
* @access private
*/
    var $_java_info = array();

    // }}}
    // {{{ isJPhone()

    /**
* returns TRUE
*
* @return boolean
* @access public
*/
    function isJPhone()
    {
        return TRUE;
    }

    // }}}
    // {{{ parse()

    /**
* parse HTTP_USER_AGENT string
*
* @access public
*/
    function parse()
    {
        $agent = explode(' ', $this->getUserAgent());
        $count = count($agent);

        if ($count > 1) {

            // J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
            $this->_packet_compliant = TRUE;
            list($this->name, $this->version, $this->_model,
                 $serial_number) = explode('/', $agent[0]);
            if ($serial_number) {
                if (!preg_match('/^SN(.+)/', $serial_number,
                                $matches)
                    ) {
                    return $this->noMatch();
                }
                $this->_serial_number = $matches[1];
            }
            list($this->_vendor, $this->_vendor_version) =
                explode('/', $agent[1]);
            for ($i = 2; $i < $count; ++$i) {
                list($key, $value) = explode('/', $agent[$i]);
                $this->_java_info[$key] = $value;
            }
        } else {

            // J-PHONE/2.0/J-DN02
            list($this->name, $this->version, $this->_model) =
                explode('/', $agent[0]);
            if ($this->_model) {
                preg_match('/J-([A-Z]+)/', $this->_model, $matches);
                $this->_vendor = $matches[1];
            }
        }
    }

    // }}}
    // {{{ makeDisplay()

    /**
* create a new Net_UserAgent_Mobile_Display class instance
*
* @return object Net_UserAgent_Mobile_Display
* @access public
* @see Net_UserAgent_Mobile_Display()
*/
    function makeDisplay()
    {
        list($width, $height) =
            explode('*', $this->getHeader('x-jphone-display'));
        $color = FALSE;
        $depth = NULL;
        if ($color_string = $this->getHeader('x-jphone-color')) {
            preg_match('/^([CG])(\d+)$/', $color_string, $matches);
            $color = $matches[1] === 'C' ? TRUE : FALSE;
            $depth = $matches[2];
        }
        return new Net_UserAgent_Mobile_Display(array(
                                                      'width' => $width,
                                                      'height' => $height,
                                                      'depth' => $depth,
                                                      'color' => $color)
                                                );
    }

    // }}}
    // {{{ getModel()

    /**
* returns name of the model like 'J-DN02'
*
* @return string
* @access public
*/
    function getModel()
    {
        return $this->_model;
    }

    // }}}
    // {{{ isPacketCompliant()

    /**
* returns whether the agent is packet connection complicant or not
*
* @return boolean
* @access public
*/
    function isPacketCompliant()
    {
        return $this->_packet_compliant;
    }

    // }}}
    // {{{ getSerialNumber()

    /**
* return terminal unique serial number. returns NULL if user forbids to send his/her serial number.
*
* @return string
* @access public
*/
    function getSerialNumber()
    {
        return $this->_serial_number;
    }

    // }}}
    // {{{ getVendor()

    /**
* returns vendor code like 'SH'
*
* @return string
* @access public
*/
    function getVendor()
    {
        return $this->_vendor;
    }

    // }}}
    // {{{ getVendorVersion()

    /**
* returns vendor version like '0001a'. returns NULL if unknown.
*
* @return string
* @access public
*/
    function getVendorVersion()
    {
        return $this->_vendor_version;
    }

    // }}}
    // {{{ getJavaInfo()

    /**
* returns array of Java profiles
*
* Array structure is something like:
*
* 'Profile' => 'MIDP-1.0',
* 'Configuration' => 'CLDC-1.0',
* 'Ext-Profile' => 'JSCL-1.1.0'
*
* @return array
* @access public
*/
    function getJavaInfo()
    {
        return $this->_java_info;
    }
}

/*
* Local Variables:
* mode: php
* coding: iso-8859-1
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* indent-tabs-mode: nil
* End:
*/
?>
Something went wrong with that request. Please try again.