Bot.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace WhichBrowser\Analyser\Header\Useragent;
  3. use WhichBrowser\Constants;
  4. use WhichBrowser\Data;
  5. trait Bot
  6. {
  7. private function &detectBot($ua)
  8. {
  9. /* Detect bots based on url in the UA string */
  10. if (preg_match('/\+https?:\/\//iu', $ua)) {
  11. $this->data->browser->reset();
  12. $this->data->os->reset();
  13. $this->data->engine->reset();
  14. $this->data->device->reset();
  15. $this->data->device->type = Constants\DeviceType::BOT;
  16. }
  17. /* Detect bots based on common markers */
  18. if (preg_match('/(?:Bot|Robot|Spider|Crawler)([\/\);]|$)/iu', $ua) && !preg_match('/CUBOT/iu', $ua)) {
  19. $this->data->browser->reset();
  20. $this->data->os->reset();
  21. $this->data->engine->reset();
  22. $this->data->device->reset();
  23. $this->data->device->type = Constants\DeviceType::BOT;
  24. }
  25. /* Detect based on a predefined list or markers */
  26. if ($bot = Data\Applications::identifyBot($ua)) {
  27. $this->data->browser = $bot;
  28. $this->data->os->reset();
  29. $this->data->engine->reset();
  30. $this->data->device->reset();
  31. $this->data->device->type = Constants\DeviceType::BOT;
  32. }
  33. return $this;
  34. }
  35. }