PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_gantry/core/gantrybrowser.class.php

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