Corrections.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace WhichBrowser\Analyser;
  3. use WhichBrowser\Constants;
  4. use WhichBrowser\Model\Version;
  5. trait Corrections
  6. {
  7. private function &applyCorrections()
  8. {
  9. if (isset($this->data->browser->name) && isset($this->data->browser->using)) {
  10. $this->hideBrowserBasedOnUsing();
  11. }
  12. if (isset($this->data->browser->name) && isset($this->data->os->name)) {
  13. $this->hideBrowserBasedOnOperatingSystem();
  14. }
  15. if (isset($this->data->browser->name) && $this->data->device->type == Constants\DeviceType::TELEVISION) {
  16. $this->hideBrowserOnDeviceTypeTelevision();
  17. }
  18. if (isset($this->data->browser->name) && $this->data->device->type == Constants\DeviceType::GAMING) {
  19. $this->hideBrowserOnDeviceTypeGaming();
  20. }
  21. if ($this->data->device->type == Constants\DeviceType::TELEVISION) {
  22. $this->hideOsOnDeviceTypeTelevision();
  23. }
  24. if (isset($this->data->browser->name) && isset($this->data->engine->name)) {
  25. $this->fixMidoriEngineName();
  26. }
  27. if (isset($this->data->browser->name) && isset($this->data->engine->name)) {
  28. $this->fixNineSkyEngineName();
  29. }
  30. if (isset($this->data->browser->name) && isset($this->data->browser->family)) {
  31. $this->hideFamilyIfEqualToBrowser();
  32. }
  33. return $this;
  34. }
  35. private function hideFamilyIfEqualToBrowser()
  36. {
  37. if ($this->data->browser->name == $this->data->browser->family->name) {
  38. unset($this->data->browser->family);
  39. }
  40. }
  41. private function fixMidoriEngineName()
  42. {
  43. if ($this->data->browser->name == 'Midori' && $this->data->engine->name != 'Webkit') {
  44. $this->data->engine->name = 'Webkit';
  45. $this->data->engine->version = null;
  46. }
  47. }
  48. private function fixNineSkyEngineName()
  49. {
  50. if ($this->data->browser->name == 'NineSky' && $this->data->engine->name != 'Webkit') {
  51. $this->data->engine->name = 'Webkit';
  52. $this->data->engine->version = null;
  53. }
  54. }
  55. private function hideBrowserBasedOnUsing()
  56. {
  57. if ($this->data->browser->name == 'Chrome') {
  58. if ($this->data->browser->isUsing('Electron') || $this->data->browser->isUsing('Qt')) {
  59. unset($this->data->browser->name);
  60. unset($this->data->browser->version);
  61. }
  62. }
  63. }
  64. private function hideBrowserBasedOnOperatingSystem()
  65. {
  66. if ($this->data->os->name == 'Series60' && $this->data->browser->name == 'Internet Explorer') {
  67. $this->data->browser->reset();
  68. $this->data->engine->reset();
  69. }
  70. if ($this->data->os->name == 'Series80' && $this->data->browser->name == 'Internet Explorer') {
  71. $this->data->browser->reset();
  72. $this->data->engine->reset();
  73. }
  74. if ($this->data->os->name == 'Lindows' && $this->data->browser->name == 'Internet Explorer') {
  75. $this->data->browser->reset();
  76. $this->data->engine->reset();
  77. }
  78. if ($this->data->os->name == 'Tizen' && $this->data->browser->name == 'Chrome') {
  79. $this->data->browser->reset([
  80. 'family' => isset($this->data->browser->family) ? $this->data->browser->family : null
  81. ]);
  82. }
  83. if ($this->data->os->name == 'Ubuntu Touch' && $this->data->browser->name == 'Chromium') {
  84. $this->data->browser->reset([
  85. 'family' => isset($this->data->browser->family) ? $this->data->browser->family : null
  86. ]);
  87. }
  88. }
  89. private function hideBrowserOnDeviceTypeGaming()
  90. {
  91. if (isset($this->data->device->model) && $this->data->device->model == 'Playstation 2' && $this->data->browser->name == 'Internet Explorer') {
  92. $this->data->browser->reset();
  93. }
  94. }
  95. private function hideBrowserOnDeviceTypeTelevision()
  96. {
  97. switch ($this->data->browser->name) {
  98. case 'Firefox':
  99. if (!$this->data->isOs('Firefox OS')) {
  100. unset($this->data->browser->name);
  101. unset($this->data->browser->version);
  102. }
  103. break;
  104. case 'Internet Explorer':
  105. $valid = false;
  106. if (isset($this->data->device->model) && in_array($this->data->device->model, [ 'WebTV' ])) {
  107. $valid = true;
  108. }
  109. if (!$valid) {
  110. unset($this->data->browser->name);
  111. unset($this->data->browser->version);
  112. }
  113. break;
  114. case 'Chrome':
  115. case 'Chromium':
  116. $valid = false;
  117. if (isset($this->data->os->name) && in_array($this->data->os->name, [ 'Google TV', 'Android' ])) {
  118. $valid = true;
  119. }
  120. if (isset($this->data->device->model) && in_array($this->data->device->model, [ 'Chromecast' ])) {
  121. $valid = true;
  122. }
  123. if (!$valid) {
  124. unset($this->data->browser->name);
  125. unset($this->data->browser->version);
  126. }
  127. break;
  128. }
  129. }
  130. private function hideOsOnDeviceTypeTelevision()
  131. {
  132. if (isset($this->data->os->name) && !in_array($this->data->os->name, [ 'Aliyun OS', 'Tizen', 'Android', 'Android TV', 'FireOS', 'Google TV', 'Firefox OS', 'OpenTV', 'webOS' ])) {
  133. $this->data->os->reset();
  134. }
  135. }
  136. }