PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/alpha/lib/includes/browser.class.php

https://github.com/dskvr/Graffitar
PHP | 553 lines | 361 code | 34 blank | 158 comment | 51 complexity | dada9df547677804aae0c584ef1033cd MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * Class to detect which browser is currently accessing the page/site
  4. * @author Paul Scott
  5. * This class is very loosely based on scripts by Gary White
  6. * @copyright Paul Scott
  7. * @package browser
  8. */
  9. class browser
  10. {
  11. /**
  12. * @var string $name
  13. */
  14. var $name = NULL;
  15. /**
  16. * @var string $version
  17. */
  18. var $version = NULL;
  19. /**
  20. * @var $useragent
  21. */
  22. var $useragent = NULL;
  23. /**
  24. * @var string $platform
  25. */
  26. var $platform;
  27. /**
  28. * @var string aol
  29. */
  30. var $aol = FALSE;
  31. /**
  32. * @var string browser
  33. */
  34. var $browsertype;
  35. /**
  36. * Class constructor
  37. * @param void
  38. * @return void
  39. */
  40. function browser()
  41. {
  42. $agent = $_SERVER['HTTP_USER_AGENT'];
  43. //set the useragent property
  44. $this->useragent = $agent;
  45. }
  46. /**
  47. * Method to get the browser details from the USER_AGENT string in
  48. * the PHP superglobals
  49. * @param void
  50. * @return string property platform
  51. */
  52. function getBrowserOS()
  53. {
  54. $win = eregi("win", $this->useragent);
  55. $linux = eregi("linux", $this->useragent);
  56. $mac = eregi("mac", $this->useragent);
  57. $os2 = eregi("OS/2", $this->useragent);
  58. $beos = eregi("BeOS", $this->useragent);
  59. //now do the check as to which matches and return it
  60. if($win)
  61. {
  62. $this->platform = "Windows";
  63. }
  64. elseif ($linux)
  65. {
  66. $this->platform = "Linux";
  67. }
  68. elseif ($mac)
  69. {
  70. $this->platform = "Macintosh";
  71. }
  72. elseif ($os2)
  73. {
  74. $this->platform = "OS/2";
  75. }
  76. elseif ($beos)
  77. {
  78. $this->platform = "BeOS";
  79. }
  80. return $this->platform;
  81. }
  82. /**
  83. * Method to test for Opera
  84. * @param void
  85. * @return property $broswer
  86. * @return property version
  87. * @return bool false on failure
  88. */
  89. function isOpera()
  90. {
  91. // test for Opera
  92. if (eregi("opera",$this->useragent))
  93. {
  94. $val = stristr($this->useragent, "opera");
  95. if (eregi("/", $val)){
  96. $val = explode("/",$val);
  97. $this->browsertype = $val[0];
  98. $val = explode(" ",$val[1]);
  99. $this->version = $val[0];
  100. }else{
  101. $val = explode(" ",stristr($val,"opera"));
  102. $this->browsertype = $val[0];
  103. $this->version = $val[1];
  104. }
  105. return TRUE;
  106. }
  107. else {
  108. return FALSE;
  109. }
  110. }
  111. /**
  112. * Method to check for FireFox
  113. * @param void
  114. * @return bool false on failure
  115. */
  116. function isFirefox()
  117. {
  118. if(eregi("Firefox", $this->useragent))
  119. {
  120. $this->browsertype = "Firefox";
  121. $val = stristr($this->useragent, "Firefox");
  122. $val = explode("/",$val);
  123. $this->version = $val[1];
  124. return true;
  125. }
  126. else {
  127. return FALSE;
  128. }
  129. }
  130. /**
  131. * Method to check for Konquerer
  132. * @param void
  133. * @return prop $browser
  134. * @return prop $version
  135. * @return bool true on success
  136. */
  137. function isKonqueror()
  138. {
  139. if(eregi("Konqueror",$this->useragent))
  140. {
  141. $val = explode(" ",stristr($this->useragent,"Konqueror"));
  142. $val = explode("/",$val[0]);
  143. $this->browsertype = $val[0];
  144. $this->version = str_replace(")","",$val[1]);
  145. return TRUE;
  146. }
  147. else {
  148. return FALSE;
  149. }
  150. }//end func
  151. /**
  152. * Method to check for Internet Explorer v1
  153. * @param void
  154. * @return bool true on success
  155. * @return prop $browsertype
  156. * @return prop $version
  157. */
  158. function isIEv1()
  159. {
  160. if(eregi("microsoft internet explorer", $this->useragent))
  161. {
  162. $this->browsertype = "MSIE";
  163. $this->version = "1.0";
  164. $var = stristr($this->useragent, "/");
  165. if (ereg("308|425|426|474|0b1", $var))
  166. {
  167. $this->version = "1.5";
  168. }
  169. return TRUE;
  170. }
  171. else {
  172. return FALSE;
  173. }
  174. }//end function
  175. /**
  176. * Method to check for Internet Explorer later than v1
  177. * @param void
  178. * @return bool true on success
  179. * @return prop $browsertype
  180. * @return prop $version
  181. */
  182. function isMSIE()
  183. {
  184. if(eregi("msie", $this->useragent) && !eregi("opera",$this->useragent))
  185. {
  186. $this->browsertype = "MSIE";
  187. $val = explode(" ",stristr($this->useragent,"msie"));
  188. $this->browsertype = $val[0];
  189. $this->version = $val[1];
  190. return TRUE;
  191. }
  192. else {
  193. return FALSE;
  194. }
  195. }//end function
  196. /**
  197. * Method to check for Galeon
  198. * @param void
  199. * @return bool true on success
  200. */
  201. function isGaleon()
  202. {
  203. if(eregi("galeon",$this->useragent))
  204. {
  205. $val = explode(" ",stristr($this->useragent,"galeon"));
  206. $val = explode("/",$val[0]);
  207. $this->browsertype = $val[0];
  208. $this->version = $val[1];
  209. return TRUE;
  210. }
  211. else {
  212. return FALSE;
  213. }
  214. }//end func
  215. /**
  216. * Now we do the tests for browsers I can't test...
  217. * If someone finds a bug, please report it ASAP to me please!
  218. */
  219. /**
  220. * Method to check for WebTV browser
  221. * @param void
  222. * @return bool true on success
  223. * @return prop $browsertype
  224. * @return prop $version
  225. */
  226. function isWebTV()
  227. {
  228. if(eregi("webtv",$this->useragent))
  229. {
  230. $val = explode("/",stristr($this->useragent,"webtv"));
  231. $this->browsertype = $val[0];
  232. $this->version = $val[1];
  233. return TRUE;
  234. }
  235. else {
  236. return FALSE;
  237. }
  238. }
  239. /**
  240. * Method to check for BeOS's NetPositive
  241. * @param void
  242. * @return bool true on success
  243. * @return prop $browsertype
  244. * @return prop $version
  245. */
  246. function isNetPositive()
  247. {
  248. if(eregi("NetPositive", $this->useragent))
  249. {
  250. $val = explode("/",stristr($this->useragent,"NetPositive"));
  251. $this->platform = "BeOS";
  252. $this->browsertype = $val[0];
  253. $this->version = $val[1];
  254. return TRUE;
  255. }
  256. else {
  257. return FALSE;
  258. }
  259. }
  260. /**
  261. * Method to check for MSPIE (Pocket IE)
  262. * @param void
  263. * @return bool true on success
  264. */
  265. function isMSPIE()
  266. {
  267. if(eregi("mspie",$this->useragent) || eregi("pocket", $this->useragent))
  268. {
  269. $val = explode(" ",stristr($this->useragent,"mspie"));
  270. $this->browsertype = "MSPIE";
  271. $this->platform = "WindowsCE";
  272. if (eregi("mspie", $this->useragent))
  273. $this->version = $val[1];
  274. else {
  275. $val = explode("/",$this->useragent);
  276. $this->version = $val[1];
  277. }
  278. return TRUE;
  279. }
  280. else {
  281. return FALSE;
  282. }
  283. }
  284. /**
  285. * Method to test for iCab
  286. * @param void
  287. * @return bool true on success
  288. */
  289. function isIcab()
  290. {
  291. if(eregi("icab",$this->useragent))
  292. {
  293. $val = explode(" ",stristr($this->useragent,"icab"));
  294. $this->browsertype = $val[0];
  295. $this->version = $val[1];
  296. return TRUE;
  297. }
  298. else {
  299. return FALSE;
  300. }
  301. }
  302. /**
  303. * Method to test for the OmniWeb Browser
  304. * @param void
  305. * @return bool True on success
  306. */
  307. function isOmniWeb()
  308. {
  309. if(eregi("omniweb",$this->useragent))
  310. {
  311. $val = explode("/",stristr($this->useragent,"omniweb"));
  312. $this->browsertype = $val[0];
  313. $this->version = $val[1];
  314. return TRUE;
  315. }
  316. else {
  317. return FALSE;
  318. }
  319. }
  320. /**
  321. * Method to check for Phoenix Browser
  322. * @param void
  323. * @return bool true on success
  324. */
  325. function isPhoenix()
  326. {
  327. if(eregi("Phoenix", $this->useragent))
  328. {
  329. $this->browsertype = "Phoenix";
  330. $val = explode("/", stristr($this->useragent,"Phoenix/"));
  331. $this->version = $val[1];
  332. return TRUE;
  333. }
  334. else {
  335. return FALSE;
  336. }
  337. }
  338. /**
  339. * Method to check for Firebird
  340. * @param void
  341. * @return bool true on success
  342. */
  343. function isFirebird()
  344. {
  345. if(eregi("firebird", $this->useragent))
  346. {
  347. $this->browsertype = "Firebird";
  348. $val = stristr($this->useragent, "Firebird");
  349. $val = explode("/",$val);
  350. $this->version = $val[1];
  351. return TRUE;
  352. }
  353. else {
  354. return FALSE;
  355. }
  356. }
  357. /**
  358. * Method to check for Mozilla alpha/beta
  359. * @param void
  360. * @return bool true on success
  361. */
  362. function isMozAlphaBeta()
  363. {
  364. if(eregi("mozilla",$this->useragent) &&
  365. eregi("rv:[0-9].[0-9][a-b]",$this->useragent) &&
  366. !eregi("netscape",$this->useragent))
  367. {
  368. $this->browsertype = "Mozilla";
  369. $val = explode(" ",stristr($this->useragent,"rv:"));
  370. eregi("rv:[0-9].[0-9][a-b]",$this->useragent,$val);
  371. $this->version = str_replace("rv:","",$val[0]);
  372. return TRUE;
  373. }
  374. else {
  375. return FALSE;
  376. }
  377. }//end function
  378. /**
  379. * Method to check for Mozilla Stable versions
  380. * @param void
  381. * @return bool true on success
  382. */
  383. function isMozStable()
  384. {
  385. if(eregi("mozilla",$this->useragent) &&
  386. eregi("rv:[0-9]\.[0-9]",$this->useragent) &&
  387. !eregi("netscape",$this->useragent))
  388. {
  389. $this->browsertype = "Mozilla";
  390. $val = explode(" ",stristr($this->useragent,"rv:"));
  391. eregi("rv:[0-9]\.[0-9]\.[0-9]",$this->useragent,$val);
  392. $this->version = str_replace("rv:","",$val[0]);
  393. return TRUE;
  394. }
  395. else {
  396. return FALSE;
  397. }
  398. }
  399. /**
  400. * Method to check for Lynx and Amaya
  401. * @param void
  402. * @return bool true on success
  403. */
  404. function isLynx()
  405. {
  406. if(eregi("libwww", $this->useragent))
  407. {
  408. if (eregi("amaya", $this->useragent))
  409. {
  410. $val = explode("/",stristr($this->useragent,"amaya"));
  411. $this->browsertype = "Amaya";
  412. $val = explode(" ", $val[1]);
  413. $this->version = $val[0];
  414. } else {
  415. $val = explode("/",$this->useragent);
  416. $this->browsertype = "Lynx";
  417. $this->version = $val[1];
  418. }
  419. return TRUE;
  420. }
  421. else {
  422. return FALSE;
  423. }
  424. }
  425. /**
  426. * method to check for safari browser
  427. * @param void
  428. * @return bool true on success
  429. */
  430. function isSafari()
  431. {
  432. if(eregi("safari", $this->useragent))
  433. {
  434. $this->browsertype = "Safari";
  435. $this->version = "";
  436. return TRUE;
  437. }
  438. else {
  439. return FALSE;
  440. }
  441. }
  442. /**
  443. * Various tests for Netscrape
  444. * @param void
  445. * @return bool true on success
  446. */
  447. function isNetscape()
  448. {
  449. if(eregi("netscape",$this->useragent))
  450. {
  451. $val = explode(" ",stristr($this->useragent,"netscape"));
  452. $val = explode("/",$val[0]);
  453. $this->browsertype = $val[0];
  454. $this->version = $val[1];
  455. return TRUE;
  456. }
  457. elseif(eregi("mozilla",$this->useragent) &&
  458. !eregi("rv:[0-9]\.[0-9]\.[0-9]",$this->useragent))
  459. {
  460. $val = explode(" ",stristr($this->useragent,"mozilla"));
  461. $val = explode("/",$val[0]);
  462. $this->browsertype = "Netscape";
  463. $this->version = $val[1];
  464. return TRUE;
  465. }
  466. else {
  467. return FALSE;
  468. }
  469. }//end func
  470. /**
  471. * Method to check for AOL connections
  472. * @param void
  473. * @return bool true on Success
  474. */
  475. function isAOL()
  476. {
  477. if (eregi("AOL", $this->useragent)){
  478. $var = stristr($this->useragent, "AOL");
  479. $var = explode(" ", $var);
  480. $this->aol = ereg_replace("[^0-9,.,a-z,A-Z]", "", $var[1]);
  481. return TRUE;
  482. }
  483. else {
  484. return FALSE;
  485. }
  486. }
  487. /**
  488. * Method to tie them all up and output something useful
  489. * @param void
  490. * @return array
  491. */
  492. function whatBrowser()
  493. {
  494. $this->getBrowserOS();
  495. $this->isOpera();
  496. $this->isFirefox();
  497. $this->isKonqueror();
  498. $this->isIEv1();
  499. $this->isMSIE();
  500. $this->isGaleon();
  501. $this->isNetPositive();
  502. $this->isMSPIE();
  503. $this->isIcab();
  504. $this->isOmniWeb();
  505. $this->isPhoenix();
  506. $this->isFirebird();
  507. $this->isLynx();
  508. $this->isSafari();
  509. //$this->isMozAlphaBeta();
  510. //$this->isMozStable();
  511. //$this->isNetscape();
  512. $this->isAOL();
  513. return array('browsertype' => $this->browsertype,
  514. 'version' => $this->version,
  515. 'platform' => $this->platform,
  516. 'AOL' => $this->aol);
  517. }
  518. }//end class
  519. ?>