UCBrowserNew.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace WhichBrowser\Analyser\Header;
  3. use WhichBrowser\Data;
  4. use WhichBrowser\Model\Family;
  5. use WhichBrowser\Model\Version;
  6. class UCBrowserNew
  7. {
  8. public function __construct($header, &$data)
  9. {
  10. $this->data =& $data;
  11. if (preg_match('/pr\(UCBrowser/u', $header)) {
  12. if (!$this->data->isBrowser('UC Browser')) {
  13. $this->data->browser->name = 'UC Browser';
  14. $this->data->browser->stock = false;
  15. $this->data->browser->version = null;
  16. if (preg_match('/pr\(UCBrowser(?:\/([0-9\.]+))/u', $header, $match)) {
  17. $this->data->browser->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  18. }
  19. }
  20. }
  21. /* Find os */
  22. if (preg_match('/pf\(Java\)/u', $header)) {
  23. if (preg_match('/dv\(([^\)]*)\)/u', $header, $match)) {
  24. if ($this->identifyBasedOnModel($match[1])) {
  25. return;
  26. }
  27. }
  28. }
  29. if (preg_match('/pf\(Linux\)/u', $header) && preg_match('/ov\((?:Android )?([0-9\.]+)/u', $header, $match)) {
  30. $this->data->os->name = 'Android';
  31. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  32. }
  33. if (preg_match('/pf\(Symbian\)/u', $header) && preg_match('/ov\(S60V([0-9])/u', $header, $match)) {
  34. if (!$this->data->isOs('Series60')) {
  35. $this->data->os->name = 'Series60';
  36. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  37. }
  38. }
  39. if (preg_match('/pf\(Windows\)/u', $header) && preg_match('/ov\(wds ([0-9]+\.[0-9]+)/u', $header, $match)) {
  40. if (!$this->data->isOs('Windows Phone')) {
  41. $this->data->os->name = 'Windows Phone';
  42. switch ($match[1]) {
  43. case '7.1':
  44. $this->data->os->version = new Version([ 'value' => '7.5' ]);
  45. break;
  46. case '8.0':
  47. $this->data->os->version = new Version([ 'value' => '8.0' ]);
  48. break;
  49. case '8.1':
  50. $this->data->os->version = new Version([ 'value' => '8.1' ]);
  51. break;
  52. case '10.0':
  53. $this->data->os->version = new Version([ 'value' => '10.0' ]);
  54. break;
  55. }
  56. }
  57. }
  58. if (preg_match('/pf\((?:42|44)\)/u', $header) && preg_match('/ov\((?:iPh OS )?(?:iOS )?([0-9\_]+)/u', $header, $match)) {
  59. if (!$this->data->isOs('iOS')) {
  60. $this->data->os->name = 'iOS';
  61. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  62. }
  63. }
  64. /* Find engine */
  65. if (preg_match('/re\(AppleWebKit\/([0-9\.]+)/u', $header, $match)) {
  66. $this->data->engine->name = 'Webkit';
  67. $this->data->engine->version = new Version([ 'value' => $match[1] ]);
  68. }
  69. /* Find device */
  70. if ($this->data->isOs('Android')) {
  71. if (preg_match('/dv\((.*)\)/uU', $header, $match)) {
  72. $match[1] = preg_replace("/\s+Build/u", '', $match[1]);
  73. $device = Data\DeviceModels::identify('android', $match[1]);
  74. if ($device) {
  75. $this->data->device = $device;
  76. }
  77. }
  78. }
  79. if ($this->data->isOs('Series60')) {
  80. if (preg_match('/dv\((?:Nokia)?([^\)]*)\)/iu', $header, $match)) {
  81. $device = Data\DeviceModels::identify('symbian', $match[1]);
  82. if ($device) {
  83. $this->data->device = $device;
  84. }
  85. }
  86. }
  87. if ($this->data->isOs('Windows Phone')) {
  88. if (preg_match('/dv\(([^\)]*)\)/u', $header, $match)) {
  89. $device = Data\DeviceModels::identify('wp', substr(strstr($match[1], ' '), 1));
  90. if ($device) {
  91. $this->data->device = $device;
  92. }
  93. }
  94. }
  95. if ($this->data->isOs('iOS')) {
  96. if (preg_match('/dv\(([^\)]*)\)/u', $header, $match)) {
  97. $device = Data\DeviceModels::identify('ios', $match[1]);
  98. if ($device) {
  99. $this->data->device = $device;
  100. }
  101. }
  102. }
  103. }
  104. private function identifyBasedOnModel($model)
  105. {
  106. $model = preg_replace('/^Nokia/iu', '', $model);
  107. $device = Data\DeviceModels::identify('symbian', $model);
  108. if ($device->identified) {
  109. $device->identified |= $this->data->device->identified;
  110. $this->data->device = $device;
  111. if (!isset($this->data->os->name) || $this->data->os->name != 'Series60') {
  112. $this->data->os->name = 'Series60';
  113. $this->data->os->version = null;
  114. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  115. }
  116. return true;
  117. }
  118. $device = Data\DeviceModels::identify('s40', $model);
  119. if ($device->identified) {
  120. $device->identified |= $this->data->device->identified;
  121. $this->data->device = $device;
  122. if (!isset($this->data->os->name) || $this->data->os->name != 'Series40') {
  123. $this->data->os->name = 'Series40';
  124. $this->data->os->version = null;
  125. }
  126. return true;
  127. }
  128. $device = Data\DeviceModels::identify('bada', $model);
  129. if ($device->identified) {
  130. $device->identified |= $this->data->device->identified;
  131. $this->data->device = $device;
  132. if (!isset($this->data->os->name) || $this->data->os->name != 'Bada') {
  133. $this->data->os->name = 'Bada';
  134. $this->data->os->version = null;
  135. }
  136. return true;
  137. }
  138. $device = Data\DeviceModels::identify('touchwiz', $model);
  139. if ($device->identified) {
  140. $device->identified |= $this->data->device->identified;
  141. $this->data->device = $device;
  142. if (!isset($this->data->os->name) || $this->data->os->name != 'Touchwiz') {
  143. $this->data->os->name = 'Touchwiz';
  144. $this->data->os->version = null;
  145. }
  146. return true;
  147. }
  148. }
  149. }