PageRenderTime 65ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Horde/Browser/imode.php

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