123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- namespace WhichBrowser\Analyser\Header\Useragent\Device;
- use WhichBrowser\Constants;
- trait Ereader
- {
- private function detectEreader($ua)
- {
- if (!preg_match('/(Kindle|Nook|Bookeen|Kobo|EBRD|PocketBook|Iriver)/ui', $ua)) {
- return;
- }
- $this->detectKindle($ua);
- $this->detectNook($ua);
- $this->detectBookeen($ua);
- $this->detectKobo($ua);
- $this->detectSonyreader($ua);
- $this->detectPocketbook($ua);
- $this->detectIriver($ua);
- }
- /* Amazon Kindle */
- private function detectKindle($ua)
- {
- if (preg_match('/Kindle/u', $ua) && !preg_match('/Fire/u', $ua)) {
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'Amazon',
- 'series' => 'Kindle',
- 'type' => Constants\DeviceType::EREADER
- ]);
- if (preg_match('/Kindle SkipStone/u', $ua)) {
- $this->data->device->model = 'Kindle Touch or later';
- } elseif (preg_match('/Kindle\/3.0\+/u', $ua)) {
- $this->data->device->model = 'Kindle 3 or later';
- } elseif (preg_match('/Kindle\/3.0/u', $ua)) {
- $this->data->device->model = 'Kindle 3';
- } elseif (preg_match('/Kindle\/2.5/u', $ua)) {
- $this->data->device->model = 'Kindle 2';
- } elseif (preg_match('/Kindle\/2.0/u', $ua)) {
- $this->data->device->model = 'Kindle 2';
- } elseif (preg_match('/Kindle\/1.0/u', $ua)) {
- $this->data->device->model = 'Kindle 1';
- }
- if (!empty($this->data->device->model)) {
- $this->data->device->generic = false;
- $this->data->device->series = null;
- }
- }
- }
- /* Barnes & Noble Nook */
- private function detectNook($ua)
- {
- if (preg_match('/nook browser/u', $ua)) {
- $this->data->os->reset([ 'name' => 'Android' ]);
- $this->data->device->setIdentification([
- 'manufacturer' => 'Barnes & Noble',
- 'series' => 'NOOK',
- 'type' => Constants\DeviceType::EREADER
- ]);
- }
- }
- /* Bookeen */
- private function detectBookeen($ua)
- {
- if (preg_match('/bookeen\/cybook/u', $ua)) {
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'Bookeen',
- 'series' => 'Cybook',
- 'type' => Constants\DeviceType::EREADER
- ]);
- }
- }
- /* Kobo */
- private function detectKobo($ua)
- {
- if (preg_match('/Kobo (eReader|Touch)/u', $ua, $match)) {
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'Kobo',
- 'series' => 'eReader',
- 'type' => Constants\DeviceType::EREADER
- ]);
- }
- }
- /* Sony Reader */
- private function detectSonyreader($ua)
- {
- if (preg_match('/EBRD([0-9]+)/u', $ua, $match)) {
- $model = null;
- switch ($match[1]) {
- case '1101':
- $model = 'PRS-T1';
- break;
- case '1102':
- $model = 'PRS-G1';
- break;
- case '1201':
- $model = 'PRS-T2';
- break;
- case '1301':
- $model = 'PRS-T3';
- break;
- }
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'Sony',
- 'model' => $model,
- 'series' => 'Reader',
- 'type' => Constants\DeviceType::EREADER
- ]);
- }
- }
- /* PocketBook */
- private function detectPocketbook($ua)
- {
- if (preg_match('/PocketBook\/([0-9]+)/u', $ua, $match)) {
- $model = null;
- switch ($match[1]) {
- case '515':
- $model = 'Mini';
- break;
- case '614':
- $model = 'Basic 2';
- break;
- case '622':
- $model = 'Touch';
- break;
- case '623':
- $model = 'Touch Lux';
- break;
- case '624':
- $model = 'Basic Touch';
- break;
- case '626':
- $model = 'Touch Lux 2';
- break;
- case '630':
- $model = 'Sense';
- break;
- case '640':
- $model = 'Aqua';
- break;
- case '650':
- $model = 'Ultra';
- break;
- case '801':
- $model = 'Color Lux';
- break;
- case '840':
- $model = 'InkPad';
- break;
- }
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'PocketBook',
- 'model' => $model,
- 'type' => Constants\DeviceType::EREADER
- ]);
- }
- }
- /* iRiver */
- private function detectIriver($ua)
- {
- if (preg_match('/Iriver ;/u', $ua)) {
- $this->data->os->reset();
- $this->data->device->setIdentification([
- 'manufacturer' => 'iRiver',
- 'series' => 'Story',
- 'type' => Constants\DeviceType::EREADER
- ]);
- if (preg_match('/EB07/u', $ua)) {
- $this->data->device->model = 'Story HD EB07';
- $this->data->device->series = null;
- $this->data->device->generic = false;
- }
- }
- }
- }
|