Useragent.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace WhichBrowser\Analyser\Header;
  3. class Useragent
  4. {
  5. use Useragent\Os, Useragent\Device, Useragent\Browser, Useragent\Application, Useragent\Using, Useragent\Engine, Useragent\Bot;
  6. public function __construct($header, &$data)
  7. {
  8. $this->data =& $data;
  9. /* Make sure we do not have a duplicate concatenated useragent string */
  10. $header = preg_replace("/^(Mozilla\/[0-9]\.[0-9].{20,})\s+Mozilla\/[0-9]\.[0-9].*$/iu", '$1', $header);
  11. /* Detect the basic information */
  12. $this->detectOperatingSystem($header)
  13. ->detectDevice($header)
  14. ->detectBrowser($header)
  15. ->detectApplication($header)
  16. ->detectUsing($header)
  17. ->detectEngine($header);
  18. /* Detect bots */
  19. if (!isset($this->options->detectBots) || $this->options->detectBots === true) {
  20. $this->detectBot($header);
  21. }
  22. /* Refine some of the information */
  23. $this->refineBrowser($header)
  24. ->refineOperatingSystem($header);
  25. }
  26. private function removeKnownPrefixes($ua)
  27. {
  28. $ua = preg_replace('/^OneBrowser\/[0-9.]+\//', '', $ua);
  29. $ua = preg_replace('/^MQQBrowser\/[0-9.]+\//', '', $ua);
  30. return $ua;
  31. }
  32. }