Ereader.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace WhichBrowser\Analyser\Header\Useragent\Device;
  3. use WhichBrowser\Constants;
  4. trait Ereader
  5. {
  6. private function detectEreader($ua)
  7. {
  8. if (!preg_match('/(Kindle|Nook|Bookeen|Kobo|EBRD|PocketBook|Iriver)/ui', $ua)) {
  9. return;
  10. }
  11. $this->detectKindle($ua);
  12. $this->detectNook($ua);
  13. $this->detectBookeen($ua);
  14. $this->detectKobo($ua);
  15. $this->detectSonyreader($ua);
  16. $this->detectPocketbook($ua);
  17. $this->detectIriver($ua);
  18. }
  19. /* Amazon Kindle */
  20. private function detectKindle($ua)
  21. {
  22. if (preg_match('/Kindle/u', $ua) && !preg_match('/Fire/u', $ua)) {
  23. $this->data->os->reset();
  24. $this->data->device->setIdentification([
  25. 'manufacturer' => 'Amazon',
  26. 'series' => 'Kindle',
  27. 'type' => Constants\DeviceType::EREADER
  28. ]);
  29. if (preg_match('/Kindle SkipStone/u', $ua)) {
  30. $this->data->device->model = 'Kindle Touch or later';
  31. } elseif (preg_match('/Kindle\/3.0\+/u', $ua)) {
  32. $this->data->device->model = 'Kindle 3 or later';
  33. } elseif (preg_match('/Kindle\/3.0/u', $ua)) {
  34. $this->data->device->model = 'Kindle 3';
  35. } elseif (preg_match('/Kindle\/2.5/u', $ua)) {
  36. $this->data->device->model = 'Kindle 2';
  37. } elseif (preg_match('/Kindle\/2.0/u', $ua)) {
  38. $this->data->device->model = 'Kindle 2';
  39. } elseif (preg_match('/Kindle\/1.0/u', $ua)) {
  40. $this->data->device->model = 'Kindle 1';
  41. }
  42. if (!empty($this->data->device->model)) {
  43. $this->data->device->generic = false;
  44. $this->data->device->series = null;
  45. }
  46. }
  47. }
  48. /* Barnes & Noble Nook */
  49. private function detectNook($ua)
  50. {
  51. if (preg_match('/nook browser/u', $ua)) {
  52. $this->data->os->reset([ 'name' => 'Android' ]);
  53. $this->data->device->setIdentification([
  54. 'manufacturer' => 'Barnes & Noble',
  55. 'series' => 'NOOK',
  56. 'type' => Constants\DeviceType::EREADER
  57. ]);
  58. }
  59. }
  60. /* Bookeen */
  61. private function detectBookeen($ua)
  62. {
  63. if (preg_match('/bookeen\/cybook/u', $ua)) {
  64. $this->data->os->reset();
  65. $this->data->device->setIdentification([
  66. 'manufacturer' => 'Bookeen',
  67. 'series' => 'Cybook',
  68. 'type' => Constants\DeviceType::EREADER
  69. ]);
  70. }
  71. }
  72. /* Kobo */
  73. private function detectKobo($ua)
  74. {
  75. if (preg_match('/Kobo (eReader|Touch)/u', $ua, $match)) {
  76. $this->data->os->reset();
  77. $this->data->device->setIdentification([
  78. 'manufacturer' => 'Kobo',
  79. 'series' => 'eReader',
  80. 'type' => Constants\DeviceType::EREADER
  81. ]);
  82. }
  83. }
  84. /* Sony Reader */
  85. private function detectSonyreader($ua)
  86. {
  87. if (preg_match('/EBRD([0-9]+)/u', $ua, $match)) {
  88. $model = null;
  89. switch ($match[1]) {
  90. case '1101':
  91. $model = 'PRS-T1';
  92. break;
  93. case '1102':
  94. $model = 'PRS-G1';
  95. break;
  96. case '1201':
  97. $model = 'PRS-T2';
  98. break;
  99. case '1301':
  100. $model = 'PRS-T3';
  101. break;
  102. }
  103. $this->data->os->reset();
  104. $this->data->device->setIdentification([
  105. 'manufacturer' => 'Sony',
  106. 'model' => $model,
  107. 'series' => 'Reader',
  108. 'type' => Constants\DeviceType::EREADER
  109. ]);
  110. }
  111. }
  112. /* PocketBook */
  113. private function detectPocketbook($ua)
  114. {
  115. if (preg_match('/PocketBook\/([0-9]+)/u', $ua, $match)) {
  116. $model = null;
  117. switch ($match[1]) {
  118. case '515':
  119. $model = 'Mini';
  120. break;
  121. case '614':
  122. $model = 'Basic 2';
  123. break;
  124. case '622':
  125. $model = 'Touch';
  126. break;
  127. case '623':
  128. $model = 'Touch Lux';
  129. break;
  130. case '624':
  131. $model = 'Basic Touch';
  132. break;
  133. case '626':
  134. $model = 'Touch Lux 2';
  135. break;
  136. case '630':
  137. $model = 'Sense';
  138. break;
  139. case '640':
  140. $model = 'Aqua';
  141. break;
  142. case '650':
  143. $model = 'Ultra';
  144. break;
  145. case '801':
  146. $model = 'Color Lux';
  147. break;
  148. case '840':
  149. $model = 'InkPad';
  150. break;
  151. }
  152. $this->data->os->reset();
  153. $this->data->device->setIdentification([
  154. 'manufacturer' => 'PocketBook',
  155. 'model' => $model,
  156. 'type' => Constants\DeviceType::EREADER
  157. ]);
  158. }
  159. }
  160. /* iRiver */
  161. private function detectIriver($ua)
  162. {
  163. if (preg_match('/Iriver ;/u', $ua)) {
  164. $this->data->os->reset();
  165. $this->data->device->setIdentification([
  166. 'manufacturer' => 'iRiver',
  167. 'series' => 'Story',
  168. 'type' => Constants\DeviceType::EREADER
  169. ]);
  170. if (preg_match('/EB07/u', $ua)) {
  171. $this->data->device->model = 'Story HD EB07';
  172. $this->data->device->series = null;
  173. $this->data->device->generic = false;
  174. }
  175. }
  176. }
  177. }