PageRenderTime 434ms CodeModel.GetById 121ms app.highlight 187ms RepoModel.GetById 82ms app.codeStats 1ms

/libraries/gantry/core/gantrybrowser.class.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip-alpes
PHP | 211 lines | 174 code | 12 blank | 25 comment | 23 complexity | 0f2de1d9aca45a42faf805617d8738c3 MD5 | raw file
  1<?php
  2/**
  3 * @package   gantry
  4 * @subpackage core
  5 * @version   3.2.22 August 3, 2012
  6 * @author    RocketTheme http://www.rockettheme.com
  7 * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
  8 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9 *
 10 * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
 11 *
 12 */
 13defined('GANTRY_VERSION') or die();
 14
 15/**
 16 * @package   gantry
 17 * @subpackage core
 18 */
 19class GantryBrowser {
 20	var $_ua;
 21
 22	var $name;
 23	var $version;
 24	var $shortversion;
 25	var $platform;
 26    var $engine;
 27    var $_checks = array();
 28
 29	function GantryBrowser() {
 30		$this->_ua = $_SERVER['HTTP_USER_AGENT'];
 31		$this->_checkPlatform();
 32		$this->_checkBrowser();
 33        $this->_checkEngine();
 34
 35		
 36		// add short version
 37		if ($this->version != 'unknown') $this->shortversion = substr($this->version, 0, strpos($this->version, '.'));
 38		else $this->shortversion = 'unknown';
 39
 40        $this->_createChecks();
 41	}
 42
 43	function _checkPlatform() {
 44		if (preg_match("/iPhone/", $this->_ua) || preg_match("/iPod/", $this->_ua)) {
 45			$this->platform = "iphone";
 46		}
 47		elseif (preg_match("/iPad/", $this->_ua)) {
 48			$this->platform = "ipad";
 49		}
 50		elseif (preg_match("/Android/", $this->_ua)) {
 51			$this->platform = "android";
 52		}
 53		elseif (preg_match("/Mobile/i", $this->_ua)) {
 54			$this->platform = "mobile";
 55		}
 56		elseif (preg_match("/win/i", $this->_ua)) {
 57			$this->platform = "win";
 58		}
 59		elseif (preg_match("/mac/i", $this->_ua)) {
 60			$this->platform = "mac";
 61		}
 62		elseif (preg_match("/linux/i", $this->_ua)) {
 63			$this->platform = "linux";
 64		} else {
 65			$this->platform = "unknown";
 66		}
 67
 68		return $this->platform;
 69	}
 70
 71    function _checkEngine(){
 72        switch($this->name){
 73            case 'ie':
 74                $this->engine = 'trident';
 75                break;
 76			case 'minefield':
 77            case 'firefox':
 78                $this->engine = 'gecko';
 79                break;
 80            case 'android':
 81            case 'ipad':
 82            case 'iphone':
 83            case 'chrome':
 84            case 'safari':
 85                $this->engine = 'webkit';
 86                break;
 87            case 'opera':
 88                $this->engine = 'presto';
 89                break;
 90            default:
 91                $this->engine = 'unknown';
 92                break;
 93        }
 94    }
 95	function _checkBrowser() {
 96		// IE
 97		if (preg_match('/msie/i', $this->_ua) && !preg_match('/opera/i', $this->_ua)) {
 98			$result = explode(' ', stristr(str_replace(';', ' ', $this->_ua), 'msie'));
 99			$this->name = 'ie';
100			$this->version = $result[1];
101		}
102		// Firefox
103		elseif (preg_match('/Firefox/', $this->_ua)) {
104			$result = explode('/', stristr($this->_ua, 'Firefox'));
105			$version = explode(' ', $result[1]);
106			$this->name = 'firefox';
107			$this->version = $version[0];
108		}
109		// Minefield
110		elseif (preg_match('/Minefield/', $this->_ua)) {
111			$result = explode('/', stristr($this->_ua, 'Minefield'));
112			$version = explode(' ', $result[1]);
113			$this->name = 'minefield';
114			$this->version = $version[0];
115		}
116		// Chrome
117		elseif (preg_match('/Chrome/', $this->_ua)) {
118			$result = explode('/', stristr($this->_ua, 'Chrome'));
119			$version = explode(' ', $result[1]);
120			$this->name = 'chrome';
121			$this->version = $version[0];
122		}
123		//Safari
124		elseif (preg_match('/Safari/', $this->_ua) && !preg_match('/iPhone/', $this->_ua) && !preg_match('/iPod/', $this->_ua) && !preg_match('/iPad/', $this->_ua)) {
125			$result = explode('/', stristr($this->_ua, 'Version'));
126			$this->name = 'safari';
127			if (isset ($result[1])) {
128				$version = explode(' ', $result[1]);
129				$this->version = $version[0];
130			} else {
131				$this->version = 'unknown';
132			}
133		}
134		// Opera
135		elseif (preg_match('/opera/i', $this->_ua)) {
136			$result = stristr($this->_ua, 'opera');
137
138			if (preg_match('/\//', $result)) {
139				$result = explode('/', $result);
140				$version = explode(' ', $result[1]);
141				$this->name = 'opera';
142				$this->version = $version[0];
143			} else {
144				$version = explode(' ', stristr($result, 'opera'));
145				$this->name = 'opera';
146				$this->version = $version[1];
147			}
148		}
149		// iPhone/iPod
150		elseif (preg_match('/iPhone/', $this->_ua) || preg_match('/iPod/', $this->_ua)) {
151			$result = explode('/', stristr($this->_ua, 'Version'));
152			$this->name = 'iphone';
153			if (isset ($result[1])) {
154				$version = explode(' ', $result[1]);
155				$this->version = $version[0];
156			} else {
157				$this->version = 'unknown';
158			}
159		}
160		// iPad
161		elseif (preg_match('/iPad/', $this->_ua)) {
162			$result = explode('/', stristr($this->_ua, 'Version'));
163			$this->name = 'ipad';
164			if (isset ($result[1])) {
165				$version = explode(' ', $result[1]);
166				$this->version = $version[0];
167			} else {
168				$this->version = 'unknown';
169			}
170		}
171		// Android
172		elseif (preg_match('/Android/', $this->_ua)) {
173			$result = explode('/', stristr($this->_ua, 'Version'));
174			$this->name = 'android';
175			if (isset ($result[1])) {
176				$version = explode(' ', $result[1]);
177				$this->version = $version[0];
178			} else {
179				$this->version = "unknown";
180			}
181		} else {
182			$this->name = "unknown";
183			$this->version = "unknown";
184		}
185	}
186
187    function _createChecks() {
188        $this->_checks = array(
189            '', // filename
190            '-' . $this->name,                                               // browser check
191            '-' . $this->platform,                                           // platform check
192            '-' . $this->engine,                                             // render engine
193            '-' . $this->name . '-' . $this->platform,                       // browser + platform check
194            '-' . $this->name . $this->shortversion,                         // short browser version check
195            '-' . $this->name . $this->version,                              // longbrowser version check
196            '-' . $this->name . $this->shortversion . '-' . $this->platform, // short browser version + platform check
197            '-' . $this->name . $this->version . '-' . $this->platform       // longbrowser version + platform check
198        );
199    }
200    
201    function getChecks($file, $keep_path = false) {
202        $checkfiles = array();
203        $ext = substr($file, strrpos($file, '.'));
204        $path = ($keep_path)?dirname($file).DS:'';
205        $filename = basename($file, $ext);
206        foreach($this->_checks as $suffix){
207            $checkfiles[] = $path.$filename.$suffix.$ext;
208        }
209        return $checkfiles;
210    }
211}