[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Browser/ -> imode.php (source)

   1  <?php
   2  /**
   3   * The Browser_imode:: class extends the Browser API by providing
   4   * specific information about Imode handsets.
   5   *
   6   * $Horde: framework/Browser/Browser/imode.php,v 1.7.12.5 2006/01/01 21:28:09 jan Exp $
   7   *
   8   * Copyright 2000-2006 Mika Tuupola
   9   * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
  10   *
  11   * See the enclosed file COPYING for license information (LGPL). If you
  12   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  13   *
  14   * @author  Chuck Hagenbuch <chuck@horde.org>
  15   * @since   Horde 3.0
  16   * @package Horde_Browser
  17   */
  18  class Browser_imode {
  19  
  20      /**
  21       * Device data. From http://www.nttdocomo.co.jp/i/tag/s5.html#5_1
  22       *
  23       * @var array
  24       */
  25      var $_data = array(
  26          'D209i' => array(
  27              'imagewidth' => 96, 'imageheight' => 90,
  28              'textwidth' => 8, 'textheight' => 7,
  29              'color' => 256,
  30              'imageformats' => array('gif')
  31          ),
  32          'F209i' => array(
  33              'imagewidth' => 96, 'imageheight' => 91,
  34              'textwidth' => 8, 'textheight' => 7,
  35              'color' => 256,
  36              'imageformats' => array('gif')
  37          ),
  38          'N209i' => array(
  39              'imagewidth' => 108, 'imageheight' => 82,
  40              'textwidth' => 9, 'textheight' => 6,
  41              'color' => 'grey',
  42              'imageformats' => array('gif')
  43          ),
  44          'P209i' => array(
  45              'imagewidth' => 96, 'imageheight' => 87,
  46              'textwidth' => 8, 'textheight' => 6,
  47              'color' => 'grey',
  48              'imageformats' => array('gif')
  49          ),
  50          'P209is' => array(
  51              'imagewidth' => 96, 'imageheight' => 87,
  52              'textwidth' => 8, 'textheight' => 6,
  53              'color' => 256,
  54              'imageformats' => array('gif')
  55          ),
  56          'R209i' => array(
  57              'imagewidth' => 96, 'imageheight' => 72,
  58              'textwidth' => 8, 'textheight' => 6,
  59              'color' => 'grey',
  60              'imageformats' => array('gif')
  61          ),
  62          'ER209i' => array(
  63              'imagewidth' => 120, 'imageheight' => 72,
  64              'textwidth' => 10, 'textheight' => 6,
  65              'color' => 'grey',
  66              'imageformats' => array('gif')
  67          ),
  68          'KO209i' => array(
  69              'imagewidth' => 96, 'imageheight' => 96,
  70              'textwidth' => 8, 'textheight' => 8,
  71              'color' => 256,
  72              'imageformats' => array('gif')
  73          ),
  74          'D210i' => array(
  75              'imagewidth' => 96, 'imageheight' => 91,
  76              'textwidth' => 8, 'textheight' => 7,
  77              'color' => 256,
  78              'imageformats' => array('gif')
  79          ),
  80          'F210i' => array(
  81              'imagewidth' => 96, 'imageheight' => 113,
  82              'textwidth' => 8, 'textheight' => 8,
  83              'color' => 256,
  84              'imageformats' => array('gif')
  85          ),
  86          'N210i' => array(
  87              'imagewidth' => 118, 'imageheight' => 113,
  88              'textwidth' => 10, 'textheight' => 8,
  89              'color' => 256,
  90              'imageformats' => array('gif')
  91          ),
  92          'P210i' => array(
  93              'imagewidth' => 96, 'imageheight' => 91,
  94              'textwidth' => 8, 'textheight' => 6,
  95              'color' => 256,
  96              'imageformats' => array('gif')
  97          ),
  98          'KO210i' => array(
  99              'imagewidth' => 96, 'imageheight' => 96,
 100              'textwidth' => 8, 'textheight' => 8,
 101              'color' => 256,
 102              'imageformats' => array('gif')
 103          ),
 104          'SO210i' => array(
 105              'imagewidth' => 120, 'imageheight' => 113,
 106              'textwidth' => 8, 'textheight' => 7,
 107              'color' => 256,
 108              'imageformats' => array('gif')
 109          ),
 110          'D501i' => array(
 111              'imagewidth' => 96, 'imageheight' => 72,
 112              'textwidth' => 8, 'textheight' => 6,
 113              'color' => 'black',
 114              'imageformats' => array('gif')
 115          ),
 116          'F501i' => array(
 117              'imagewidth' => 112, 'imageheight' => 84,
 118              'textwidth' => 8, 'textheight' => 6,
 119              'color' => 'black',
 120              'imageformats' => array('gif')
 121          ),
 122          'N501i' => array(
 123              'imagewidth' => 118, 'imageheight' => 128,
 124              'textwidth' => 10, 'textheight' =>10,
 125              'color' => 'black',
 126              'imageformats' => array('gif')
 127          ),
 128          'P501i' => array(
 129              'imagewidth' => 96, 'imageheight' => 120,
 130              'textwidth' => 8, 'textheight' => 8,
 131              'color' => 'black',
 132              'imageformats' => array('gif')
 133          ),
 134          'D502i' => array(
 135              'imagewidth' => 96, 'imageheight' => 90,
 136              'textwidth' => 8, 'textheight' => 7,
 137              'color' => 256,
 138              'imageformats' => array('gif')
 139          ),
 140          'F502i' => array(
 141              'imagewidth' => 96, 'imageheight' => 91,
 142              'textwidth' => 8, 'textheight' => 7,
 143              'color' => 256,
 144              'imageformats' => array('gif')
 145          ),
 146          'F502it' => array(
 147              'imagewidth' => 96, 'imageheight' => 91,
 148              'textwidth' => 8, 'textheight' => 7,
 149              'color' => 256,
 150              'imageformats' => array('gif')
 151          ),
 152          'N502i' => array(
 153              'imagewidth' => 118, 'imageheight' => 128,
 154              'textwidth' => 10, 'textheight' => 10,
 155              'color' => 'grey',
 156              'imageformats' => array('gif')
 157          ),
 158          'N502it' => array(
 159              'imagewidth' => 118, 'imageheight' => 128,
 160              'textwidth' => 10, 'textheight' => 10,
 161              'color' => 256,
 162              'imageformats' => array('gif')
 163          ),
 164          'P502i' => array(
 165              'imagewidth' => 96, 'imageheighth' => 117,
 166              'textwidth' => 8, 'textheight' => 8,
 167              'color' => 'grey',
 168              'imageformats' => array('gif')
 169          ),
 170          'NM502i' => array(
 171              'imagewidth' => 111, 'imageheight' => 77,
 172              'textwidth' => 8, 'textheight' => 6,
 173              'color' => 'black',
 174              'imageformats' => array('gif')
 175          ),
 176          'SO502i' => array(
 177              'imagewidth' => 120, 'imageheight' => 120,
 178              'textwidth' => 8, 'textheight' => 8,
 179              'color' => 'grey',
 180              'imageformats' => array('gif')
 181          ),
 182          'SO502iwm' => array(
 183              'imagewidth' => 120, 'imageheight' => 113,
 184              'textwidth' => 8, 'textheight' => 7,
 185              'color' => 256,
 186              'imageformats' => array('gif')
 187          ),
 188          'F503i' => array(
 189              'imagewidth' => 120, 'imageheight' => 130,
 190              'textwidth' => 10, 'textheight' => 10,
 191              'color' => 256,
 192              'imageformats' => array('gif')
 193          ),
 194          'F503iS' => array(
 195              'imagewidth' => 120, 'imageheight' => 130,
 196              'textwidth' => 12, 'textheight' => 12,
 197              'color' => 4096,
 198              'imageformats' => array('gif')
 199          ),
 200          'P503i' => array(
 201              'imagewidth' => 120, 'imageheight' => 130,
 202              'textwidth' => 12, 'textheight' => 10,
 203              'color' => 256,
 204              'imageformats' => array('gif')
 205          ),
 206          'P503iS' => array(
 207              'imagewidth' => 120, 'imageheight' => 130,
 208              'textwidth' => 12, 'textheight' => 10,
 209              'color' => 256,
 210              'imageformats' => array('gif')
 211          ),
 212          'SO503i' => array(
 213              'imagewidth' => 120, 'imageheight' => 113,
 214              'textwidth' => 8.5, 'textheight' => 7,
 215              'color' => 65536,
 216              'imageformats' => array('gif')
 217          ),
 218          'D503i' => array(
 219              'imagewidth' => 132, 'imageheight' => 126,
 220              'textwidth' => 8, 'textheight' => 7,
 221              'color' => 4096,
 222              'imageformats' => array('gif')
 223          ),
 224          'N503i' => array(
 225              'imagewidth' => 118, 'imageheight' => 128,
 226              'textwidth' => 10, 'textheight' => 10,
 227              'color' => 4096,
 228              'imageformats' => array('gif', 'jpg')
 229          ),
 230          'N503iS' => array(
 231              'imagewidth' => 118, 'imageheight' => 128,
 232              'textwidth' => 10, 'textheight' => 10,
 233              'color' => 4096,
 234              'imageformats' => array('gif', 'jpg')
 235          ),
 236          'N691i' => array(
 237              'imagewidth' => 96, 'imageheight' => 72,
 238              'textwidth' => 8, 'textheight' => 6,
 239              'color' => 'grey',
 240              'imageformats' => array('gif')
 241          ),
 242          'SH821i' => array(
 243              'imagewidth' => 96, 'imageheight' => 78,
 244              'textwidth' => 8, 'textheight' => 6,
 245              'color' => 256,
 246              'imageformats' => array('gif')
 247          ),
 248          'N821i' => array(
 249              'imagewidth' => 118, 'imageheight' => 128,
 250              'textwidth' => 10, 'textheight' => 10,
 251              'color' => 'grey',
 252              'imageformats' => array('gif')
 253          ),
 254          'P821i' => array(
 255              'imagewidth' => 118, 'imageheight' => 128,
 256              'textwidth' => 10, 'textheight' => 10,
 257              'color' => 'grey',
 258              'imageformats' => array('gif')
 259          ),
 260          'safe' => array(
 261              'imagewidth' => 94, 'imageheight' => 72,
 262              'textwidth' => 8, 'textheight' => 6,
 263              'color' => 'black',
 264              'imageformats' => array('gif')
 265          )
 266      );
 267  
 268      var $_manufacturerlist = array(
 269          'D' => 'Mitsubishi',
 270          'P' => 'Panasonic (Matsushita)',
 271          'NM' => 'Nokia',
 272          'SO' => 'Sony',
 273          'F' => 'Fujitsu',
 274          'N' => 'Nec',
 275          'SH' => 'Sharp',
 276          'ER' => 'Ericsson',
 277          'R' => 'Japan Radio',
 278          'KO' => 'Kokusai (Hitachi)'
 279      );
 280  
 281      var $_extra = array(
 282          't' => 'Transport layer',
 283          'e' => 'English language',
 284          's' => 'Second version'
 285      );
 286  
 287      var $_user_agent;
 288      var $_model;
 289      var $_manufacturer;
 290      var $_httpversion;
 291      var $_cache = 5;
 292  
 293      /**
 294       * Does not handle bogus user_agents or most of the other error
 295       * situation properly yet.
 296       *
 297       * Example usage:
 298       *   $ua = &new Browser_imode($_SERVEr['HTTP_USER_AGENT']);
 299       *
 300       * @param string $input  The user agent to match.
 301       */
 302      function Browser_imode($input)
 303      {
 304          $_error = 0;
 305          $temp = explode('/', $input);
 306  
 307          $this->_user_agent = $input;
 308          $this->_httpversion = $temp[1];
 309          $this->_model = $temp[2];
 310          if ($temp[3]) {
 311              $this->_cache = substr($temp[3], 1);
 312          }
 313  
 314          preg_match('/(^[a-zA-Z]+)([0-9]+i)(.*)\/?(.*)/', $this->_model, $matches);
 315  
 316          // @TODO: Fix situation of unknown manufacturer. Implement
 317          // extrainfo properly.
 318          $this->_manufacturer = $this->_manufacturerlist[$matches[1]];
 319          $this->_extra = $matches[3];
 320  
 321          if (!($this->_data[$this->_model])) {
 322              $_error = PEAR::raiseError('Unknown User Agent');
 323          }
 324      }
 325  
 326      /**
 327       * Example usage:
 328       *  $imagedim    = $ua->getImageDimensions();
 329       *  $imagewidth  = $imagedim[0];
 330       *  $imageheight = $imagedim[1];
 331       *
 332       * @return array  The maximum imagewidth and imageheight that
 333       *                fit on the handset screen without scrolling.
 334       */
 335      function getImageDimensions()
 336      {
 337          $data = $this->_data[$this->_model];
 338          return array($data['imagewidth'], $data['imageheight']);
 339      }
 340  
 341      /**
 342       * Example usage:
 343       *  $textdim    = $ua->getTextDimensions();
 344       *  $textwidth  = $textdim[0];
 345       *  $textheight = $textdim[1];
 346       *
 347       * @return array  The Maximum textwidth and textheight that
 348       *                fit on the handset screen without scrolling.
 349       */
 350      function getTextDimensions()
 351      {
 352          return array($this->_data[$this->_model]['textwidth'],
 353                       $this->_data[$this->_model]['textheight']);
 354      }
 355  
 356      /**
 357       * @return integer  The amount of handset cache in kilobytes.
 358       */
 359      function getCache()
 360      {
 361          return (int)$this->_cache;
 362      }
 363  
 364      function getManufacturer()
 365      {
 366          return $this->_manufacturer;
 367      }
 368  
 369      function getExtra()
 370      {
 371          return $this->_extra;
 372      }
 373  
 374      function getImageFormats()
 375      {
 376          return $this->_data[$this->_model]['imageformats'];
 377      }
 378  
 379      /**
 380       * @return integer  Which color model the handset supports.
 381       *   Values have the following meaning:
 382       *     0 -> black and white
 383       *     1 -> 4 tone greyscale
 384       *     2 -> 256 color
 385       */
 386      function getColor()
 387      {
 388          return $this->_data[$this->_model]['color'];
 389      }
 390  
 391      function getHTTPVersion()
 392      {
 393          return $this->_httpversion;
 394      }
 395  
 396      function isColor()
 397      {
 398          return $this->_data[$this->_model]['color'] == 256;
 399      }
 400  
 401      function isGreyScale()
 402      {
 403          return $this->_data[$this->_model]['color'] == 'grey';
 404      }
 405  
 406      function isBlackAndWhite()
 407      {
 408          return $this->_data[$this->_model]['color'] == 'black';
 409      }
 410  
 411  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7