Media.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace WhichBrowser\Analyser\Header\Useragent\Device;
  3. use WhichBrowser\Constants;
  4. use WhichBrowser\Model\Version;
  5. trait Media
  6. {
  7. private function detectMedia($ua)
  8. {
  9. if (!preg_match('/(Archos|Zune|Walkman)/ui', $ua)) {
  10. return;
  11. }
  12. $this->detectArchos($ua);
  13. $this->detectZune($ua);
  14. $this->detectWalkman($ua);
  15. }
  16. /* Archos Generation 4, 5 and 6 */
  17. private function detectArchos($ua)
  18. {
  19. /* Generation 4 */
  20. if (preg_match('/Archos A([67]04)WIFI\//u', $ua, $match)) {
  21. $this->data->os->reset();
  22. $this->data->device->setIdentification([
  23. 'manufacturer' => 'Archos',
  24. 'model' => $match[1] . ' WiFi',
  25. 'type' => Constants\DeviceType::MEDIA
  26. ]);
  27. }
  28. /* Generation 5 */
  29. if (preg_match('/ARCHOS; GOGI; a([67]05f?);/u', $ua, $match)) {
  30. $this->data->os->reset();
  31. $this->data->device->setIdentification([
  32. 'manufacturer' => 'Archos',
  33. 'model' => $match[1] . ' WiFi',
  34. 'type' => Constants\DeviceType::MEDIA
  35. ]);
  36. }
  37. /* Generation 6 without Android */
  38. if (preg_match('/ARCHOS; GOGI; G6-?(S|H|L|3GP);/u', $ua, $match)) {
  39. $this->data->os->reset();
  40. $this->data->device->setIdentification([
  41. 'manufacturer' => 'Archos',
  42. 'type' => Constants\DeviceType::MEDIA
  43. ]);
  44. switch ($match[1]) {
  45. case '3GP':
  46. $this->data->device->model = '5 3G+';
  47. break;
  48. case 'S':
  49. case 'H':
  50. $this->data->device->model = '5';
  51. break;
  52. case 'L':
  53. $this->data->device->model = '7';
  54. break;
  55. }
  56. }
  57. /* Generation 6 with Android */
  58. if (preg_match('/ARCHOS; GOGI; A5[SH]; Version ([0-9]\.[0-9])/u', $ua, $match)) {
  59. $version = new Version([ 'value' => $match[1] ]);
  60. $this->data->os->reset([
  61. 'name' => 'Android',
  62. 'version' => new Version([ 'value' => $version->is('<', '1.7') ? '1.5' : '1.6' ])
  63. ]);
  64. $this->data->device->setIdentification([
  65. 'manufacturer' => 'Archos',
  66. 'model' => '5',
  67. 'type' => Constants\DeviceType::MEDIA
  68. ]);
  69. }
  70. }
  71. /* Microsoft Zune */
  72. private function detectZune($ua)
  73. {
  74. if (preg_match('/Microsoft ZuneHD/u', $ua)) {
  75. $this->data->os->reset();
  76. $this->data->device->setIdentification([
  77. 'manufacturer' => 'Microsoft',
  78. 'model' => 'Zune HD',
  79. 'type' => Constants\DeviceType::MEDIA
  80. ]);
  81. }
  82. }
  83. /* Sony Walkman */
  84. private function detectWalkman($ua)
  85. {
  86. if (preg_match('/Walkman\/(NW-[A-Z0-9]+)/u', $ua, $match)) {
  87. $this->data->device->setIdentification([
  88. 'manufacturer' => 'Sony',
  89. 'model' => $match[1] . ' Walkman',
  90. 'type' => Constants\DeviceType::MEDIA
  91. ]);
  92. }
  93. }
  94. }