https-bitbucket.org-bityvip-alpes /libraries/gantry/core/gantrybrowser.class.php

Language PHP Lines 211
MD5 Hash 0f2de1d9aca45a42faf805617d8738c3 Estimated Cost $4,255 (why?)
Repository https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip-alpes.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
 * @package   gantry
 * @subpackage core
 * @version   3.2.22 August 3, 2012
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 *
 * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
 *
 */
defined('GANTRY_VERSION') or die();

/**
 * @package   gantry
 * @subpackage core
 */
class GantryBrowser {
	var $_ua;

	var $name;
	var $version;
	var $shortversion;
	var $platform;
    var $engine;
    var $_checks = array();

	function GantryBrowser() {
		$this->_ua = $_SERVER['HTTP_USER_AGENT'];
		$this->_checkPlatform();
		$this->_checkBrowser();
        $this->_checkEngine();

		
		// add short version
		if ($this->version != 'unknown') $this->shortversion = substr($this->version, 0, strpos($this->version, '.'));
		else $this->shortversion = 'unknown';

        $this->_createChecks();
	}

	function _checkPlatform() {
		if (preg_match("/iPhone/", $this->_ua) || preg_match("/iPod/", $this->_ua)) {
			$this->platform = "iphone";
		}
		elseif (preg_match("/iPad/", $this->_ua)) {
			$this->platform = "ipad";
		}
		elseif (preg_match("/Android/", $this->_ua)) {
			$this->platform = "android";
		}
		elseif (preg_match("/Mobile/i", $this->_ua)) {
			$this->platform = "mobile";
		}
		elseif (preg_match("/win/i", $this->_ua)) {
			$this->platform = "win";
		}
		elseif (preg_match("/mac/i", $this->_ua)) {
			$this->platform = "mac";
		}
		elseif (preg_match("/linux/i", $this->_ua)) {
			$this->platform = "linux";
		} else {
			$this->platform = "unknown";
		}

		return $this->platform;
	}

    function _checkEngine(){
        switch($this->name){
            case 'ie':
                $this->engine = 'trident';
                break;
			case 'minefield':
            case 'firefox':
                $this->engine = 'gecko';
                break;
            case 'android':
            case 'ipad':
            case 'iphone':
            case 'chrome':
            case 'safari':
                $this->engine = 'webkit';
                break;
            case 'opera':
                $this->engine = 'presto';
                break;
            default:
                $this->engine = 'unknown';
                break;
        }
    }
	function _checkBrowser() {
		// IE
		if (preg_match('/msie/i', $this->_ua) && !preg_match('/opera/i', $this->_ua)) {
			$result = explode(' ', stristr(str_replace(';', ' ', $this->_ua), 'msie'));
			$this->name = 'ie';
			$this->version = $result[1];
		}
		// Firefox
		elseif (preg_match('/Firefox/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Firefox'));
			$version = explode(' ', $result[1]);
			$this->name = 'firefox';
			$this->version = $version[0];
		}
		// Minefield
		elseif (preg_match('/Minefield/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Minefield'));
			$version = explode(' ', $result[1]);
			$this->name = 'minefield';
			$this->version = $version[0];
		}
		// Chrome
		elseif (preg_match('/Chrome/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Chrome'));
			$version = explode(' ', $result[1]);
			$this->name = 'chrome';
			$this->version = $version[0];
		}
		//Safari
		elseif (preg_match('/Safari/', $this->_ua) && !preg_match('/iPhone/', $this->_ua) && !preg_match('/iPod/', $this->_ua) && !preg_match('/iPad/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Version'));
			$this->name = 'safari';
			if (isset ($result[1])) {
				$version = explode(' ', $result[1]);
				$this->version = $version[0];
			} else {
				$this->version = 'unknown';
			}
		}
		// Opera
		elseif (preg_match('/opera/i', $this->_ua)) {
			$result = stristr($this->_ua, 'opera');

			if (preg_match('/\//', $result)) {
				$result = explode('/', $result);
				$version = explode(' ', $result[1]);
				$this->name = 'opera';
				$this->version = $version[0];
			} else {
				$version = explode(' ', stristr($result, 'opera'));
				$this->name = 'opera';
				$this->version = $version[1];
			}
		}
		// iPhone/iPod
		elseif (preg_match('/iPhone/', $this->_ua) || preg_match('/iPod/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Version'));
			$this->name = 'iphone';
			if (isset ($result[1])) {
				$version = explode(' ', $result[1]);
				$this->version = $version[0];
			} else {
				$this->version = 'unknown';
			}
		}
		// iPad
		elseif (preg_match('/iPad/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Version'));
			$this->name = 'ipad';
			if (isset ($result[1])) {
				$version = explode(' ', $result[1]);
				$this->version = $version[0];
			} else {
				$this->version = 'unknown';
			}
		}
		// Android
		elseif (preg_match('/Android/', $this->_ua)) {
			$result = explode('/', stristr($this->_ua, 'Version'));
			$this->name = 'android';
			if (isset ($result[1])) {
				$version = explode(' ', $result[1]);
				$this->version = $version[0];
			} else {
				$this->version = "unknown";
			}
		} else {
			$this->name = "unknown";
			$this->version = "unknown";
		}
	}

    function _createChecks() {
        $this->_checks = array(
            '', // filename
            '-' . $this->name,                                               // browser check
            '-' . $this->platform,                                           // platform check
            '-' . $this->engine,                                             // render engine
            '-' . $this->name . '-' . $this->platform,                       // browser + platform check
            '-' . $this->name . $this->shortversion,                         // short browser version check
            '-' . $this->name . $this->version,                              // longbrowser version check
            '-' . $this->name . $this->shortversion . '-' . $this->platform, // short browser version + platform check
            '-' . $this->name . $this->version . '-' . $this->platform       // longbrowser version + platform check
        );
    }
    
    function getChecks($file, $keep_path = false) {
        $checkfiles = array();
        $ext = substr($file, strrpos($file, '.'));
        $path = ($keep_path)?dirname($file).DS:'';
        $filename = basename($file, $ext);
        foreach($this->_checks as $suffix){
            $checkfiles[] = $path.$filename.$suffix.$ext;
        }
        return $checkfiles;
    }
}
Back to Top