PageRenderTime 49ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/program/include/crystal_browser.php

https://github.com/crystalmail/Crystal-Mail
PHP | 73 lines | 40 code | 8 blank | 25 comment | 24 complexity | f5a10d07bde50b92196a796260feecb2 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------+
  4. | program/include/crystal_browser.php |
  5. | |
  6. | This file is part of the RoundCube Webmail client |
  7. | Copyright (C) 2007-2009, RoundCube Dev. - Switzerland |
  8. | Licensed under the GNU GPL |
  9. | |
  10. | PURPOSE: |
  11. | Class representing the client browser's properties |
  12. | |
  13. +-----------------------------------------------------------------------+
  14. | Author: Thomas Bruederli <crystalmail@gmail.com> |
  15. +-----------------------------------------------------------------------+
  16. $Id: crystal_browser.php 3212 2010-01-18 19:15:28Z alec $
  17. */
  18. /**
  19. * crystal_browser
  20. *
  21. * Provide details about the client's browser based on the User-Agent header
  22. *
  23. * @package Core
  24. */
  25. class crystal_browser
  26. {
  27. function __construct()
  28. {
  29. $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
  30. $this->ver = 0;
  31. $this->win = stristr($HTTP_USER_AGENT, 'win');
  32. $this->mac = stristr($HTTP_USER_AGENT, 'mac');
  33. $this->linux = stristr($HTTP_USER_AGENT, 'linux');
  34. $this->unix = stristr($HTTP_USER_AGENT, 'unix');
  35. $this->opera = stristr($HTTP_USER_AGENT, 'opera');
  36. $this->ns4 = stristr($HTTP_USER_AGENT, 'mozilla/4') && !stristr($HTTP_USER_AGENT, 'msie');
  37. $this->ns = ($this->ns4 || stristr($HTTP_USER_AGENT, 'netscape'));
  38. $this->ie = stristr($HTTP_USER_AGENT, 'compatible; msie') && !$this->opera;
  39. $this->mz = stristr($HTTP_USER_AGENT, 'mozilla/5');
  40. $this->chrome = stristr($HTTP_USER_AGENT, 'chrome');
  41. $this->khtml = stristr($HTTP_USER_AGENT, 'khtml');
  42. $this->safari = ($this->khtml || stristr($HTTP_USER_AGENT, 'safari'));
  43. if ($this->ns || $this->chrome) {
  44. $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/i', $HTTP_USER_AGENT, $regs);
  45. $this->ver = $test ? (float)$regs[2] : 0;
  46. }
  47. else if ($this->mz) {
  48. $test = preg_match('/rv:([0-9.]+)/', $HTTP_USER_AGENT, $regs);
  49. $this->ver = $test ? (float)$regs[1] : 0;
  50. }
  51. else if ($this->ie || $this->opera) {
  52. $test = preg_match('/(msie|opera) ([0-9.]+)/i', $HTTP_USER_AGENT, $regs);
  53. $this->ver = $test ? (float)$regs[2] : 0;
  54. }
  55. if (preg_match('/ ([a-z]{2})-([a-z]{2})/i', $HTTP_USER_AGENT, $regs))
  56. $this->lang = $regs[1];
  57. else
  58. $this->lang = 'en';
  59. $this->dom = ($this->mz || $this->safari || ($this->ie && $this->ver>=5) || ($this->opera && $this->ver>=7));
  60. $this->pngalpha = $this->mz || $this->safari || ($this->ie && $this->ver>=5.5) ||
  61. ($this->ie && $this->ver>=5 && $this->mac) || ($this->opera && $this->ver>=7) ? true : false;
  62. }
  63. }