PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/mc/rt_missioncontrol_j15/lib/rtbrowser.class.php

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