1<?php 2 3/** 4 +-----------------------------------------------------------------------+ 5 | This file is part of the Roundcube Webmail client | 6 | | 7 | Copyright (C) The Roundcube Dev Team | 8 | | 9 | Licensed under the GNU General Public License version 3 or | 10 | any later version with exceptions for skins & plugins. | 11 | See the README file for a full license statement. | 12 | | 13 | PURPOSE: | 14 | Class representing the client browser's properties | 15 +-----------------------------------------------------------------------+ 16 | Author: Thomas Bruederli <roundcube@gmail.com> | 17 +-----------------------------------------------------------------------+ 18*/ 19 20/** 21 * Provide details about the client's browser based on the User-Agent header 22 * 23 * @package Framework 24 * @subpackage Utils 25 */ 26class rcube_browser 27{ 28 /** @var float $ver Browser version */ 29 public $ver = 0; 30 31 /** @var bool $win Browser OS is Windows */ 32 public $win = false; 33 34 /** @var bool $mac Browser OS is Mac */ 35 public $mac = false; 36 37 /** @var bool $linux Browser OS is Linux */ 38 public $linux = false; 39 40 /** @var bool $unix Browser OS is Unix */ 41 public $unix = false; 42 43 /** @var bool $webkit Browser uses WebKit engine */ 44 public $webkit = false; 45 46 /** @var bool $opera Browser is Opera */ 47 public $opera = false; 48 49 /** @var bool $chrome Browser is Chrome */ 50 public $chrome = false; 51 52 /** @var bool $ie Browser is Internet Explorer */ 53 public $ie = false; 54 55 /** @var bool $edge Browser is Edge */ 56 public $edge = false; 57 58 /** @var bool $safari Browser is Safari */ 59 public $safari = false; 60 61 /** @var bool $mz Browser is Mozilla Firefox */ 62 public $mz = false; 63 64 65 /** 66 * Object constructor 67 */ 68 public function __construct() 69 { 70 $HTTP_USER_AGENT = !empty($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : ''; 71 72 // Operating system detection 73 $this->win = strpos($HTTP_USER_AGENT, 'win') != false; 74 $this->mac = strpos($HTTP_USER_AGENT, 'mac') != false; 75 $this->linux = strpos($HTTP_USER_AGENT, 'linux') != false; 76 $this->unix = strpos($HTTP_USER_AGENT, 'unix') != false; 77 78 // Engine detection 79 $this->webkit = strpos($HTTP_USER_AGENT, 'applewebkit') !== false; 80 $this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false || ($this->webkit && strpos($HTTP_USER_AGENT, 'opr/') !== false); 81 $this->edge = strpos($HTTP_USER_AGENT, 'edge/') !== false; 82 $this->ie = !$this->opera && !$this->edge && (strpos($HTTP_USER_AGENT, 'compatible; msie') !== false || strpos($HTTP_USER_AGENT, 'trident/') !== false); 83 $this->chrome = !$this->opera && !$this->edge && strpos($HTTP_USER_AGENT, 'chrome') !== false; 84 $this->safari = !$this->opera && !$this->chrome && !$this->edge 85 && ($this->webkit || strpos($HTTP_USER_AGENT, 'safari') !== false); 86 $this->mz = !$this->ie && !$this->edge && !$this->safari && !$this->chrome && !$this->opera 87 && strpos($HTTP_USER_AGENT, 'mozilla') !== false; 88 89 // Version detection 90 if ($this->edge && preg_match('/edge\/([0-9.]+)/', $HTTP_USER_AGENT, $regs)) { 91 $this->ver = (float) $regs[1]; 92 } 93 else if ($this->opera && preg_match('/(opera|opr)(\s*|\/)([0-9.]+)/', $HTTP_USER_AGENT, $regs)) { 94 $this->ver = (float) $regs[3]; 95 } 96 else if ($this->safari && preg_match('/(version|safari)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs)) { 97 $this->ver = (float) $regs[1]; 98 } 99 else if (preg_match('/(chrome|khtml|version|msie|rv:)(\s*|\/)([0-9.]+)/', $HTTP_USER_AGENT, $regs)) { 100 $this->ver = (float) $regs[3]; 101 } 102 } 103} 104