Os.php 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  1. <?php
  2. namespace WhichBrowser\Analyser\Header\Useragent;
  3. use WhichBrowser\Constants;
  4. use WhichBrowser\Data;
  5. use WhichBrowser\Model\Family;
  6. use WhichBrowser\Model\Version;
  7. trait Os
  8. {
  9. private function &detectOperatingSystem($ua)
  10. {
  11. $this->detectUnix($ua);
  12. $this->detectLinux($ua);
  13. $this->detectBsd($ua);
  14. $this->detectDarwin($ua);
  15. $this->detectWindows($ua);
  16. $this->detectAndroid($ua);
  17. $this->detectChromeos($ua);
  18. $this->detectBlackberry($ua);
  19. $this->detectWebos($ua);
  20. $this->detectSymbian($ua);
  21. $this->detectNokiaOs($ua);
  22. $this->detectTizen($ua);
  23. $this->detectSailfish($ua);
  24. $this->detectBada($ua);
  25. $this->detectBrew($ua);
  26. $this->detectQtopia($ua);
  27. $this->detectOpenTV($ua);
  28. $this->detectRemainingOperatingSystems($ua);
  29. return $this;
  30. }
  31. private function &refineOperatingSystem($ua)
  32. {
  33. $this->determineAndroidVersionBasedOnBuild($ua);
  34. return $this;
  35. }
  36. /* Darwin */
  37. private function detectDarwin($ua)
  38. {
  39. /* iOS */
  40. if (preg_match('/\(iOS;/u', $ua)) {
  41. $this->data->os->name = 'iOS';
  42. $this->data->device->type = Constants\DeviceType::MOBILE;
  43. }
  44. if (preg_match('/(iPhone|iPad|iPod)/u', $ua) && !preg_match('/like iPhone/u', $ua)) {
  45. $this->data->os->name = 'iOS';
  46. if (preg_match('/CPU like Mac OS X/u', $ua, $match)) {
  47. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  48. }
  49. if (preg_match('/OS (.*) like Mac OS X/u', $ua, $match)) {
  50. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  51. }
  52. if (preg_match('/iPhone OS ([0-9._]*);/u', $ua, $match)) {
  53. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  54. }
  55. if (preg_match('/iPhone Simulator;/u', $ua)) {
  56. $this->data->device->type = Constants\DeviceType::EMULATOR;
  57. } else {
  58. if (preg_match('/(iPad|iPhone( 3GS| 3G| 4S| 4| 5)?|iPod( touch)?)/u', $ua, $match)) {
  59. $device = Data\DeviceModels::identify('ios', $match[0]);
  60. if ($device) {
  61. $this->data->device = $device;
  62. }
  63. }
  64. if (preg_match('/(iPad|iPhone|iPod)[0-9],[0-9]/u', $ua, $match)) {
  65. $device = Data\DeviceModels::identify('ios', $match[0]);
  66. if ($device) {
  67. $this->data->device = $device;
  68. }
  69. }
  70. }
  71. } /* OS X */
  72. elseif (preg_match('/Mac OS X/u', $ua) || preg_match('/;os=Mac/u', $ua)) {
  73. $this->data->os->name = 'OS X';
  74. if (preg_match('/Mac OS X (10[0-9\._]*)/u', $ua, $match)) {
  75. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]), 'details' => 2 ]);
  76. }
  77. if (preg_match('/;os=Mac (10[0-9[\.,]*)/u', $ua, $match)) {
  78. $this->data->os->version = new Version([ 'value' => str_replace(',', '.', $match[1]), 'details' => 2 ]);
  79. }
  80. $this->data->device->type = Constants\DeviceType::DESKTOP;
  81. }
  82. /* Darwin */
  83. if (preg_match('/Darwin(?:\/([0-9]+).[0-9]+)?/u', $ua, $match)) {
  84. if (preg_match('/\(X11;/u', $ua)) {
  85. /* Darwin */
  86. $this->data->os->name = 'Darwin';
  87. $this->data->device->type = Constants\DeviceType::DESKTOP;
  88. } elseif (preg_match('/\((?:x86_64|i386|Power%20Macintosh)\)/u', $ua)) {
  89. /* OS X */
  90. $this->data->os->name = 'OS X';
  91. $this->data->device->type = Constants\DeviceType::DESKTOP;
  92. if (isset($match[1])) {
  93. $version = Data\Darwin::getVersion('osx', $match[1]);
  94. if ($version) {
  95. $this->data->os->version = new Version($version);
  96. }
  97. if (preg_match('/CFNetwork\/([0-9\.]+)/u', $ua, $match)) {
  98. $version = Data\CFNetwork::getVersion('osx', $match[1]);
  99. if ($version) {
  100. $this->data->os->version = new Version($version);
  101. }
  102. }
  103. }
  104. } else {
  105. /* iOS */
  106. $this->data->os->name = 'iOS';
  107. $this->data->device->type = Constants\DeviceType::MOBILE;
  108. if (isset($match[1])) {
  109. $version = Data\Darwin::getVersion('ios', $match[1]);
  110. if ($version) {
  111. $this->data->os->version = new Version($version);
  112. }
  113. if (preg_match('/CFNetwork\/([0-9\.]+)/u', $ua, $match)) {
  114. $version = Data\CFNetwork::getVersion('ios', $match[1]);
  115. if ($version) {
  116. $this->data->os->version = new Version($version);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. /* Mac OS */
  123. if (preg_match('/\(Macintosh;/u', $ua) && !preg_match('/OS X/u', $ua)) {
  124. $this->data->os->name = 'Mac OS';
  125. $this->data->device->type = Constants\DeviceType::DESKTOP;
  126. }
  127. }
  128. /* Android */
  129. private function detectAndroid($ua)
  130. {
  131. /* Android */
  132. if (preg_match('/Andr[0o]id/ui', $ua)) {
  133. $falsepositive = false;
  134. /* Prevent the Mobile IE 11 Franken-UA from matching Android */
  135. if (preg_match('/IEMobile\/1/u', $ua)) {
  136. $falsepositive = true;
  137. }
  138. if (preg_match('/Windows Phone 10/u', $ua)) {
  139. $falsepositive = true;
  140. }
  141. /* Prevent from OSes that claim to be 'like' Android from matching */
  142. if (preg_match('/like Android/u', $ua)) {
  143. $falsepositive = true;
  144. }
  145. if (preg_match('/COS like Android/u', $ua)) {
  146. $falsepositive = false;
  147. }
  148. if (!$falsepositive) {
  149. $this->data->os->name = 'Android';
  150. $this->data->os->version = new Version();
  151. if (preg_match('/Andr[0o]id(?: )?(?:AllPhone_|CyanogenMod_|OUYA )?(?:\/)?v?([0-9.]+)/ui', str_replace('-update', ',', $ua), $match)) {
  152. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  153. }
  154. if (preg_match('/Android [0-9][0-9].[0-9][0-9].[0-9][0-9]\(([^)]+)\);/u', str_replace('-update', ',', $ua), $match)) {
  155. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  156. }
  157. if (preg_match('/Android Eclair/u', $ua)) {
  158. $this->data->os->version = new Version([ 'value' => '2.0', 'details' => 3 ]);
  159. }
  160. if (preg_match('/Android KeyLimePie/u', $ua)) {
  161. $this->data->os->version = new Version([ 'value' => '4.4', 'details' => 3 ]);
  162. }
  163. if (preg_match('/Android (?:L|4.4.99);/u', $ua)) {
  164. $this->data->os->version = new Version([ 'value' => '5', 'details' => 3, 'alias' => 'L' ]);
  165. }
  166. if (preg_match('/Android (?:M|5.[01].99);/u', $ua)) {
  167. $this->data->os->version = new Version([ 'value' => '6', 'details' => 3, 'alias' => 'M' ]);
  168. }
  169. if (preg_match('/Android (?:N|6.0.99);/u', $ua)) {
  170. $this->data->os->version = new Version([ 'value' => '7', 'details' => 3, 'alias' => 'N' ]);
  171. }
  172. $this->data->device->type = Constants\DeviceType::MOBILE;
  173. if ($this->data->os->version->toFloat() >= 3) {
  174. $this->data->device->type = Constants\DeviceType::TABLET;
  175. }
  176. if ($this->data->os->version->toFloat() >= 4 && preg_match('/Mobile/u', $ua)) {
  177. $this->data->device->type = Constants\DeviceType::MOBILE;
  178. }
  179. $candidates = [];
  180. if (preg_match('/Build/ui', $ua)) {
  181. /* Normal Android useragent strings */
  182. if (preg_match('/; [a-z][a-zA-Z][-_][a-zA-Z][a-zA-Z] ([^;]*[^;\s])\s+(?:BUILD|Build|build)/u', $ua, $match)) {
  183. $candidates[] = $match[1];
  184. }
  185. if (preg_match('/Android [A-Za-z]+; (?:[a-zA-Z][a-zA-Z](?:[-_][a-zA-Z][a-zA-Z])?) Build\/([^\/]*)\//u', $ua, $match)) {
  186. $candidates[] = $match[1];
  187. }
  188. if (preg_match('/;\+? ?(?:\*\*)?([^;]*[^;\s]);?\s+(?:BUILD|Build|build)/u', $ua, $match)) {
  189. $candidates[] = $match[1];
  190. }
  191. } elseif (preg_match('/Release\//ui', $ua)) {
  192. /* WAP style useragent strings */
  193. if (preg_match('/^(?U)([^\/]+)(?U)(?:(?:_CMCC_TD|_CMCC|_TD|_TDLTE|_LTE)?\/[^\/]*)? Linux\/[0-9.+]+ Android\/[0-9.]+/u', $this->removeKnownPrefixes($ua), $match)) {
  194. $candidates[] = $match[1];
  195. } else if (preg_match('/^(?U)([^\/]+)(?U)(?:(?:_CMCC_TD|_CMCC|_TD|_TDLTE|_LTE)?\/[^\/]*)? Android(_OS)?\/[0-9.]+/u', $this->removeKnownPrefixes($ua), $match)) {
  196. $candidates[] = $match[1];
  197. } else if (preg_match('/^(?U)([^\/]+)(?U)(?:(?:_CMCC_TD|_CMCC|_TD|_TDLTE|_LTE)?\/[^\/]*)? Release\/[0-9.]+/u', $this->removeKnownPrefixes($ua), $match)) {
  198. $candidates[] = $match[1];
  199. }
  200. } elseif (preg_match('/Mozilla\//ui', $ua)) {
  201. /* Old Android useragent strings */
  202. if (preg_match('/Linux; (?:U; )?Android [^;]+; (?:[a-zA-Z][a-zA-Z](?:[-_][a-zA-Z][a-zA-Z])?; )?(?:[^;]+; ?)?([^)\/;]+)\)/u', $ua, $match)) {
  203. $candidates[] = $match[1];
  204. } elseif (preg_match('/\(([^;]+);U;Android\/[^;]+;[0-9]+\*[0-9]+;CTC\/2.0\)/u', $ua, $match)) {
  205. $candidates[] = $match[1];
  206. }
  207. } else {
  208. /* Other applications */
  209. if (preg_match('/[34]G Explorer\/[0-9.]+ \(Linux;Android [0-9.]+,([^\)]+)\)/u', $ua, $match)) {
  210. $candidates[] = $match[1];
  211. }
  212. if (preg_match('/GetJarSDK\/.*android\/[0-9.]+ \([^;]+; [^;]+; ([^\)]+)\)$/u', $ua, $match)) {
  213. $candidates[] = $match[1];
  214. }
  215. }
  216. $candidates = array_unique($candidates);
  217. for ($c = 0; $c < count($candidates); $c++) {
  218. if (preg_match('/^[a-zA-Z][a-zA-Z](?:[-_][a-zA-Z][a-zA-Z])?$/u', $candidates[$c])) {
  219. unset($candidates[$c]);
  220. continue;
  221. }
  222. if (preg_match('/^Android [0-9\.]+$/u', $candidates[$c])) {
  223. unset($candidates[$c]);
  224. continue;
  225. }
  226. $candidates[$c] = preg_replace('/^[a-zA-Z][a-zA-Z][-_][a-zA-Z][a-zA-Z]\s+/u', '', $candidates[$c]);
  227. $candidates[$c] = preg_replace('/(.*) - [0-9\.]+ - (?:with Google Apps - )?API [0-9]+ - [0-9]+x[0-9]+/', '\\1', $candidates[$c]);
  228. $candidates[$c] = preg_replace('/^sprd-/u', '', $candidates[$c]);
  229. }
  230. $candidates = array_unique($candidates);
  231. if (count($candidates)) {
  232. $this->data->device->model = $candidates[0];
  233. $this->data->device->identified |= Constants\Id::PATTERN;
  234. for ($c = 0; $c < count($candidates); $c++) {
  235. $device = Data\DeviceModels::identify('android', $candidates[$c]);
  236. if ($device->identified) {
  237. $device->identified |= $this->data->device->identified;
  238. $this->data->device = $device;
  239. break;
  240. }
  241. }
  242. }
  243. if (preg_match('/HP eStation/u', $ua)) {
  244. $this->data->device->manufacturer = 'HP';
  245. $this->data->device->model = 'eStation';
  246. $this->data->device->type = Constants\DeviceType::PRINTER;
  247. $this->data->device->identified |= Constants\Id::MATCH_UA;
  248. $this->data->device->generic = false;
  249. }
  250. }
  251. }
  252. if (preg_match('/\(Linux; (?:U; )?(?:([0-9.]+); )?(?:[a-zA-Z][a-zA-Z](?:[-_][a-zA-Z][a-zA-Z])?; )?([^;]+) Build/u', $ua, $match)) {
  253. $falsepositive = false;
  254. if ($match[2] == 'OpenTV') {
  255. $falsepositive = true;
  256. }
  257. if (!$falsepositive) {
  258. $this->data->device->type = Constants\DeviceType::MOBILE;
  259. $this->data->device->model = $match[2];
  260. $this->data->os->name = 'Android';
  261. if (!empty($match[1])) {
  262. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  263. }
  264. $device = Data\DeviceModels::identify('android', $match[2]);
  265. if ($device->identified) {
  266. $device->identified |= Constants\Id::PATTERN;
  267. $device->identified |= $this->data->device->identified;
  268. $this->data->device = $device;
  269. }
  270. }
  271. }
  272. if (preg_match('/Linux x86_64; ([^;\)]+)(?:; [a-zA-Z][a-zA-Z](?:[-_][a-zA-Z][a-zA-Z])?)?\) AppleWebKit\/534.24 \(KHTML, like Gecko\) Chrome\/11.0.696.34 Safari\/534.24/u', $ua, $match)) {
  273. $device = Data\DeviceModels::identify('android', $match[1]);
  274. if ($device->identified) {
  275. $device->identified |= Constants\Id::PATTERN;
  276. $device->identified |= $this->data->device->identified;
  277. $this->data->os->name = 'Android';
  278. $this->data->device = $device;
  279. }
  280. }
  281. if (preg_match('/\(Linux; U; Linux Ventana; [^;]+; ([^;]+) Build/u', $ua, $match)) {
  282. $this->data->device->type = Constants\DeviceType::MOBILE;
  283. $this->data->device->model = $match[1];
  284. $device = Data\DeviceModels::identify('android', $match[1]);
  285. if ($device->identified) {
  286. $device->identified |= Constants\Id::PATTERN;
  287. $device->identified |= $this->data->device->identified;
  288. $this->data->os->name = 'Android';
  289. $this->data->device = $device;
  290. }
  291. }
  292. /* Aliyun OS */
  293. if (preg_match('/Aliyun/u', $ua) || preg_match('/YunOs/ui', $ua)) {
  294. $this->data->os->name = 'Aliyun OS';
  295. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  296. $this->data->os->version = new Version();
  297. if (preg_match('/YunOs[ \/]([0-9.]+)/iu', $ua, $match)) {
  298. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  299. }
  300. if (preg_match('/AliyunOS ([0-9.]+)/u', $ua, $match)) {
  301. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  302. }
  303. $this->data->device->type = Constants\DeviceType::MOBILE;
  304. if (preg_match('/; ([^;]*[^;\s])\s+Build/u', $ua, $match)) {
  305. $this->data->device->model = $match[1];
  306. }
  307. if (isset($this->data->device->model)) {
  308. $this->data->device->identified |= Constants\Id::PATTERN;
  309. $device = Data\DeviceModels::identify('android', $this->data->device->model);
  310. if ($device->identified) {
  311. $device->identified |= $this->data->device->identified;
  312. $this->data->device = $device;
  313. }
  314. }
  315. }
  316. if (preg_match('/Android/u', $ua)) {
  317. if (preg_match('/Android v(1.[0-9][0-9])_[0-9][0-9].[0-9][0-9]-/u', $ua, $match)) {
  318. $this->data->os->name = 'Aliyun OS';
  319. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  320. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  321. }
  322. if (preg_match('/Android[ \/](1.[0-9].[0-9].[0-9]+)-R?T/u', $ua, $match)) {
  323. $this->data->os->name = 'Aliyun OS';
  324. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  325. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  326. }
  327. if (preg_match('/Android ([12].[0-9].[0-9]+)-R-20[0-9]+/u', $ua, $match)) {
  328. $this->data->os->name = 'Aliyun OS';
  329. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  330. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 3 ]);
  331. }
  332. if (preg_match('/Android 20[0-9]+\./u', $ua, $match)) {
  333. $this->data->os->name = 'Aliyun OS';
  334. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  335. $this->data->os->version = null;
  336. }
  337. }
  338. /* Baidu Yi */
  339. if (preg_match('/Baidu Yi/u', $ua)) {
  340. $this->data->os->name = 'Baidu Yi';
  341. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  342. $this->data->os->version = null;
  343. }
  344. /* Google TV */
  345. if (preg_match('/GoogleTV/u', $ua)) {
  346. $this->data->os->name = 'Google TV';
  347. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  348. $this->data->device->type = Constants\DeviceType::TELEVISION;
  349. if (preg_match('/GoogleTV [0-9\.]+; ?([^;]*[^;\s])\s+Build/u', $ua, $match)) {
  350. $this->data->device->model = $match[1];
  351. }
  352. if (isset($this->data->device->model) && $this->data->device->model) {
  353. $this->data->device->identified |= Constants\Id::PATTERN;
  354. $device = Data\DeviceModels::identify('android', $this->data->device->model);
  355. if ($device->identified) {
  356. $device->identified |= $this->data->device->identified;
  357. $this->data->device = $device;
  358. }
  359. }
  360. }
  361. /* LeOS */
  362. if (preg_match('/LeOS/u', $ua)) {
  363. $this->data->os->name = 'LeOS';
  364. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  365. if (preg_match('/LeOS([0-9\.]*)/u', $ua, $match)) {
  366. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  367. }
  368. $this->data->device->type = Constants\DeviceType::TABLET;
  369. if (preg_match('/LeOS[0-9\.]+; [^;]+; (.*) Build/u', $ua, $match)) {
  370. $this->data->device->model = $match[1];
  371. }
  372. if (isset($this->data->device->model) && $this->data->device->model) {
  373. $this->data->device->identified |= Constants\Id::PATTERN;
  374. $device = Data\DeviceModels::identify('android', $this->data->device->model);
  375. if ($device->identified) {
  376. $device->identified |= $this->data->device->identified;
  377. $this->data->device = $device;
  378. }
  379. }
  380. }
  381. /* WoPhone */
  382. if (preg_match('/WoPhone/u', $ua)) {
  383. $this->data->os->name = 'WoPhone';
  384. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  385. if (preg_match('/WoPhone\/([0-9\.]*)/u', $ua, $match)) {
  386. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  387. }
  388. $this->data->device->type = Constants\DeviceType::MOBILE;
  389. }
  390. /* COS */
  391. if (preg_match('/(COS|(China|Chinese) Operating System)/ui', $ua)) {
  392. if (preg_match('/COS[\/ ]?([0-9]\.[0-9.]+)/ui', $ua, $match)) {
  393. $this->data->os->name = 'COS';
  394. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  395. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  396. } elseif (preg_match('/(?:\(|; )(?:China|Chinese) Operating System ([0-9]\.[0-9.]*);/ui', $ua, $match)) {
  397. $this->data->os->name = 'COS';
  398. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  399. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  400. } elseif (preg_match('/COS like Android/ui', $ua, $match)) {
  401. $this->data->os->name = 'COS';
  402. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  403. $this->data->os->version = null;
  404. $this->data->device->type = Constants\DeviceType::MOBILE;
  405. } elseif (preg_match('/(COS like Android|COSBrowser\/|\(COS;|\(COS 998;)/ui', $ua, $match)) {
  406. $this->data->os->name = 'COS';
  407. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  408. }
  409. }
  410. /* RemixOS */
  411. if (preg_match('/RemixOS/u', $ua)) {
  412. $this->data->os->name = 'Remix OS';
  413. $this->data->os->version = null;
  414. $this->data->os->family = new Family([ 'name' => 'Android' ]);
  415. if (preg_match('/RemixOS ([0-9]\.[0-9])/u', $ua, $match)) {
  416. switch ($match[1]) {
  417. case '5.1':
  418. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  419. break;
  420. case '6.0':
  421. $this->data->os->version = new Version([ 'value' => '2.0' ]);
  422. break;
  423. }
  424. }
  425. $this->data->device->type = Constants\DeviceType::DESKTOP;
  426. }
  427. }
  428. private function determineAndroidVersionBasedOnBuild($ua)
  429. {
  430. if ($this->data->isOs('Android')) {
  431. if (preg_match('/Build\/([^\);]+)/u', $ua, $match)) {
  432. $version = Data\BuildIds::identify($match[1]);
  433. if ($version) {
  434. if (!isset($this->data->os->version) || $this->data->os->version == null || $this->data->os->version->value == null || $version->toFloat() < $this->data->os->version->toFloat()) {
  435. $this->data->os->version = $version;
  436. }
  437. /* Special case for Android L */
  438. if ($version->toFloat() == 5) {
  439. $this->data->os->version = $version;
  440. }
  441. }
  442. $this->data->os->build = $match[1];
  443. }
  444. }
  445. }
  446. /* Windows */
  447. private function detectWindows($ua)
  448. {
  449. if (preg_match('/(Windows|WinNT|WinCE|WinMobile|Win ?[9MX]|Win(16|32))/u', $ua)) {
  450. $this->data->os->name = 'Windows';
  451. $this->data->device->type = Constants\DeviceType::DESKTOP;
  452. /* Windows NT */
  453. if (preg_match('/Windows 2000/u', $ua)) {
  454. $this->data->os->version = new Version([ 'value' => '5.0', 'alias' => '2000' ]);
  455. }
  456. if (preg_match('/(Windows XP|WinXP)/u', $ua)) {
  457. $this->data->os->version = new Version([ 'value' => '5.1', 'alias' => 'XP' ]);
  458. }
  459. if (preg_match('/Windows Vista/u', $ua)) {
  460. $this->data->os->version = new Version([ 'value' => '6.0', 'alias' => 'Vista' ]);
  461. }
  462. if (preg_match('/(?:Windows NT |WinNT)([0-9][0-9]?\.[0-9])/u', $ua, $match)) {
  463. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  464. switch ($match[1]) {
  465. case '10.1':
  466. case '10.0':
  467. case '6.4':
  468. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => '10' ]);
  469. break;
  470. case '6.3':
  471. if (preg_match('/; ARM;/u', $ua)) {
  472. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'RT 8.1' ]);
  473. } else {
  474. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => '8.1' ]);
  475. }
  476. break;
  477. case '6.2':
  478. if (preg_match('/; ARM;/u', $ua)) {
  479. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'RT' ]);
  480. } else {
  481. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => '8' ]);
  482. }
  483. break;
  484. case '6.1':
  485. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => '7' ]);
  486. break;
  487. case '6.0':
  488. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'Vista' ]);
  489. break;
  490. case '5.2':
  491. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'Server 2003' ]);
  492. break;
  493. case '5.1':
  494. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'XP' ]);
  495. break;
  496. case '5.0':
  497. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => '2000' ]);
  498. break;
  499. default:
  500. $this->data->os->version = new Version([ 'value' => $match[1], 'alias' => 'NT ' . $match[1] ]);
  501. break;
  502. }
  503. $this->detectWindowsOemManufacturer($ua);
  504. }
  505. /* Windows */
  506. if (preg_match('/(Windows 95|Win95)/u', $ua)) {
  507. $this->data->os->version = new Version([ 'value' => '4.0', 'alias' => '95' ]);
  508. }
  509. if (preg_match('/(Windows 98|Win98)/u', $ua)) {
  510. $this->data->os->version = new Version([ 'value' => '4.1', 'alias' => '98' ]);
  511. }
  512. if (preg_match('/(Windows M[eE]|WinME)/u', $ua)) {
  513. $this->data->os->version = new Version([ 'value' => '4.9', 'alias' => 'ME' ]);
  514. }
  515. if (preg_match('/(?:Windows|Win 9x) (([1234]\.[0-9])[0-9\.]*)/u', $ua, $match)) {
  516. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  517. switch ($match[2]) {
  518. case '4.0':
  519. $this->data->os->version = new Version([ 'value' => '4.0', 'alias' => '95' ]);
  520. break;
  521. case '4.1':
  522. $this->data->os->version = new Version([ 'value' => '4.1', 'alias' => '98' ]);
  523. break;
  524. case '4.9':
  525. $this->data->os->version = new Version([ 'value' => '4.9', 'alias' => 'ME' ]);
  526. break;
  527. }
  528. }
  529. /* Windows Mobile and Windows Phone */
  530. if (preg_match('/WPDesktop/u', $ua)) {
  531. $this->data->os->name = 'Windows Phone';
  532. $this->data->os->version = new Version([ 'value' => '8.0', 'details' => 2 ]);
  533. $this->data->device->type = Constants\DeviceType::MOBILE;
  534. $this->data->browser->mode = 'desktop';
  535. }
  536. if (preg_match('/WP7/u', $ua)) {
  537. $this->data->os->name = 'Windows Phone';
  538. $this->data->os->version = new Version([ 'value' => '7', 'details' => 1 ]);
  539. $this->data->device->type = Constants\DeviceType::MOBILE;
  540. $this->data->browser->mode = 'desktop';
  541. }
  542. if (preg_match('/WinMobile/u', $ua)) {
  543. $this->data->os->name = 'Windows Mobile';
  544. $this->data->device->type = Constants\DeviceType::MOBILE;
  545. if (preg_match('/WinMobile\/([0-9.]*)/u', $ua, $match)) {
  546. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  547. }
  548. }
  549. if (preg_match('/(Windows CE|WindowsCE|WinCE)/u', $ua)) {
  550. $this->data->device->type = Constants\DeviceType::MOBILE;
  551. if (preg_match('/ IEMobile/u', $ua)) {
  552. $this->data->os->name = 'Windows Mobile';
  553. if (preg_match('/ IEMobile\/9/u', $ua)) {
  554. $this->data->os->name = 'Windows Phone';
  555. $this->data->os->version = new Version([ 'value' => '7.5', 'details' => 2 ]);
  556. }
  557. if (preg_match('/ IEMobile 8/u', $ua)) {
  558. $this->data->os->version = new Version([ 'value' => '6.5', 'details' => 2 ]);
  559. }
  560. if (preg_match('/ IEMobile 7/u', $ua)) {
  561. $this->data->os->version = new Version([ 'value' => '6.1', 'details' => 2 ]);
  562. }
  563. if (preg_match('/ IEMobile 6/u', $ua)) {
  564. $this->data->os->version = new Version([ 'value' => '6.0', 'details' => 2 ]);
  565. }
  566. } else {
  567. $this->data->os->name = 'Windows CE';
  568. if (preg_match('/WindowsCEOS\/([0-9.]*)/u', $ua, $match)) {
  569. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  570. }
  571. if (preg_match('/Windows CE ([0-9.]*)/u', $ua, $match)) {
  572. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  573. }
  574. }
  575. $model = null;
  576. if (empty($model) && preg_match('/IEMobile [0-9.]+\) ?(?:PPC; |SP; |Smartphone; )?(?:[0-9]+[Xx][0-9]+;? )?(?:VZW; )?([^;\(]+)/u', $ua, $match)) {
  577. if (!preg_match('/(Profile\/MIDP|UNTRUSTED)/u', $match[1])) {
  578. $model = $match[1];
  579. }
  580. }
  581. if (empty($model) && preg_match('/IEMobile [0-9.]+\) (?:PPC|SP|Smartphone); (?:[0-9]+[Xx][0-9]+;? )([^;]+) Profile\/MIDP/u', $ua, $match)) {
  582. $model = $match[1];
  583. }
  584. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; (?:PPC|SP|Smartphone); [0-9]+x[0-9]+; ([^;\)]+)\)$/u', $ua, $match)) {
  585. $model = $match[1];
  586. }
  587. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; (?:PPC|SP|Smartphone); [0-9]+x[0-9]+; ([^;]+); (?:PPC|OpVer)/u', $ua, $match)) {
  588. $model = $match[1];
  589. }
  590. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; (?:PPC|SP|Smartphone); ([^;]+) Profile\/MIDP/u', $ua, $match)) {
  591. $model = $match[1];
  592. }
  593. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; (?:PPC|SP|Smartphone) ([^;\(]+)[;\/] [0-9]+x[0-9]+/u', $ua, $match)) {
  594. $model = $match[1];
  595. }
  596. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; ([^;\(]+); [0-9]+x[0-9]+\)/u', $ua, $match)) {
  597. if (!preg_match('/^(Smartphone|PPC$)/u', $match[1])) {
  598. $model = $match[1];
  599. }
  600. }
  601. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; ([^;\(]+);? ?(?:PPC|SP|Smartphone); ?[0-9]+x[0-9]+/u', $ua, $match)) {
  602. if (!preg_match('/^(MIDP-2.0)/u', $match[1])) {
  603. $model = $match[1];
  604. }
  605. }
  606. if (empty($model) && preg_match('/MSIE [0-9.]+; Windows CE; ([^;\)]+)(?:; (?:PPC|SP|Smartphone); [0-9]+x[0-9]+)?\)( \[[a-zA-Z\-]+\])?$/u', $ua, $match)) {
  607. if (!preg_match('/^(IEMobile|MIDP-2.0|Smartphone|PPC$)/u', $match[1])) {
  608. $model = $match[1];
  609. }
  610. }
  611. if (!empty($model)) {
  612. $model = preg_replace('/(HTC\/|Toshiba\/)/', '', $model);
  613. $this->data->device->model = $model;
  614. $this->data->device->identified |= Constants\Id::PATTERN;
  615. $this->data->os->name = 'Windows Mobile';
  616. $device = Data\DeviceModels::identify('wm', $model);
  617. if ($device->identified) {
  618. $device->identified |= $this->data->device->identified;
  619. $this->data->device = $device;
  620. }
  621. } else {
  622. if (empty($model) && preg_match('/Windows CE [^;]+; Trident\/[^;]+; IEMobile[\/ ][^;]+[\);] ([A-Z\s]+); ?([^\/\),]+)/ui', $ua, $match)) {
  623. $model = $match[2];
  624. }
  625. if (!empty($model)) {
  626. $this->data->device->model = $model;
  627. $this->data->device->identified |= Constants\Id::PATTERN;
  628. $this->data->os->name = 'Windows Phone';
  629. $device = Data\DeviceModels::identify('wp', $model);
  630. if ($device->identified) {
  631. $device->identified |= $this->data->device->identified;
  632. $this->data->device = $device;
  633. }
  634. }
  635. }
  636. }
  637. if (preg_match('/Microsoft Windows; (PPC|Smartphone)/u', $ua)) {
  638. $this->data->os->name = 'Windows Mobile';
  639. $this->data->device->type = Constants\DeviceType::MOBILE;
  640. }
  641. if (preg_match('/Windows CE; (PPC|Smartphone)/u', $ua)) {
  642. $this->data->os->name = 'Windows Mobile';
  643. $this->data->device->type = Constants\DeviceType::MOBILE;
  644. }
  645. /* Detect models in common places */
  646. if (preg_match('/Windows ?Mobile/u', $ua)) {
  647. $this->data->os->name = 'Windows Mobile';
  648. $this->data->device->type = Constants\DeviceType::MOBILE;
  649. if (preg_match('/Windows ?Mobile[\/ ]([0-9.]*)/u', $ua, $match)) {
  650. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  651. }
  652. if (preg_match('/Windows Mobile; (?:SHARP\/)?([^;]+); (?:PPC|Smartphone);/u', $ua, $match)) {
  653. $this->data->device->model = $match[1];
  654. $this->data->device->identified |= Constants\Id::PATTERN;
  655. $device = Data\DeviceModels::identify('wm', $match[1]);
  656. if ($device->identified) {
  657. $device->identified |= $this->data->device->identified;
  658. $this->data->device = $device;
  659. }
  660. }
  661. if (preg_match('/\(([^;]+); U; Windows Mobile/u', $ua, $match)) {
  662. $this->data->device->model = $match[1];
  663. $this->data->device->identified |= Constants\Id::PATTERN;
  664. $device = Data\DeviceModels::identify('wm', $match[1]);
  665. if ($device->identified) {
  666. $device->identified |= $this->data->device->identified;
  667. $this->data->device = $device;
  668. }
  669. }
  670. }
  671. if (preg_match('/(Windows Phone|Windows NT 1[0-9]\.[0-9]; ARM|WPDesktop|ZuneWP7)/u', $ua)) {
  672. $this->data->os->name = 'Windows Phone';
  673. $this->data->device->type = Constants\DeviceType::MOBILE;
  674. if (preg_match('/Windows Phone(?: OS)?[ \/]([0-9.]*)/u', $ua, $match)) {
  675. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  676. if (intval($match[1]) < 7) {
  677. $this->data->os->name = 'Windows Mobile';
  678. }
  679. }
  680. /* Windows Mobile 6.5 */
  681. if (preg_match('/Windows NT 5.1; ([^;]+); Windows Phone/u', $ua, $match)) {
  682. $this->data->device->model = $match[1];
  683. $this->data->device->identified |= Constants\Id::PATTERN;
  684. $device = Data\DeviceModels::identify('wm', $match[1]);
  685. if ($device->identified) {
  686. $device->identified |= $this->data->device->identified;
  687. $this->data->device = $device;
  688. }
  689. }
  690. /* Windows Phone 7 (buggy) */
  691. if (preg_match('/Windows Phone OS [^;]+; Trident\/[^;]+; IEMobile[\/ ][^;]+[\);] ([A-Z\s]+); ?([^\/\),]+)/ui', $ua, $match)) {
  692. $this->data->device->manufacturer = $match[1];
  693. $this->data->device->model = $match[2];
  694. $this->data->device->identified |= Constants\Id::PATTERN;
  695. $device = Data\DeviceModels::identify('wp', $match[2]);
  696. if ($device->identified) {
  697. $device->identified |= $this->data->device->identified;
  698. $this->data->device = $device;
  699. }
  700. }
  701. /* Windows Phone 7 and 8 */
  702. if (preg_match('/IEMobile\/[^;]+;(?: ARM; Touch; )?(?:rv:[0-9]+; )?(?: WpsLondonTest; )?\s*([^;\s][^;\)]*);\s*([^;\)\s][^;\)]*)[;|\)]/u', $ua, $match)) {
  703. $this->data->device->manufacturer = $match[1];
  704. $this->data->device->model = $match[2];
  705. $this->data->device->identified |= Constants\Id::PATTERN;
  706. $device = Data\DeviceModels::identify('wp', $match[2]);
  707. if ($device->identified) {
  708. $device->identified |= $this->data->device->identified;
  709. $this->data->device = $device;
  710. }
  711. }
  712. /* Windows Phone 10 */
  713. if (preg_match('/Windows Phone 1[0-9]\.[0-9]; Android [0-9\.]+; (?:WebView\/[0-9\.]+; )?([^;\s][^;]*);\s*([^;\)\s][^;\)]*)[;|\)]/u', $ua, $match)) {
  714. $this->data->device->manufacturer = $match[1];
  715. $this->data->device->model = $match[2];
  716. $this->data->device->identified |= Constants\Id::PATTERN;
  717. $device = Data\DeviceModels::identify('wp', $match[2]);
  718. if ($device->identified) {
  719. $device->identified |= $this->data->device->identified;
  720. $this->data->device = $device;
  721. }
  722. }
  723. /* Windows Phone 10 Continuum */
  724. if (preg_match('/Windows NT 1[0-9]\.[0-9]; ARM; ([^;\)\s][^;\)]*)\)/u', $ua, $match)) {
  725. $this->data->device->model = $match[1];
  726. $this->data->device->identified |= Constants\Id::PATTERN;
  727. $device = Data\DeviceModels::identify('wp', $match[1]);
  728. if ($device->identified) {
  729. $device->identified |= $this->data->device->identified;
  730. $this->data->device = $device;
  731. }
  732. $this->data->device->type = Constants\DeviceType::DESKTOP;
  733. }
  734. /* Third party browsers */
  735. if (preg_match('/IEMobile\/[^;]+;(?: ARM; Touch; )?\s*(?:[^\/]+\/[^\/]+);\s*([^;\s][^;]*);\s*([^;\)\s][^;\)]*)[;|\)]/u', $ua, $match)) {
  736. $this->data->device->manufacturer = $match[1];
  737. $this->data->device->model = $match[2];
  738. $this->data->device->identified |= Constants\Id::PATTERN;
  739. $device = Data\DeviceModels::identify('wp', $match[2]);
  740. if ($device->identified) {
  741. $device->identified |= $this->data->device->identified;
  742. $this->data->device = $device;
  743. }
  744. }
  745. if (preg_match('/\(Windows Phone OS\/[0-9\.]+; ([^:]+):([^;]+); [a-z]+(?:\-[a-z]+)?\)/iu', $ua, $match)) {
  746. $this->data->device->manufacturer = $match[1];
  747. $this->data->device->model = $match[2];
  748. $this->data->device->identified |= Constants\Id::PATTERN;
  749. $device = Data\DeviceModels::identify('wp', $match[2]);
  750. if ($device->identified) {
  751. $device->identified |= $this->data->device->identified;
  752. $this->data->device = $device;
  753. }
  754. }
  755. /* Desktop mode of WP 8.1 */
  756. if (preg_match('/WPDesktop;\s*([^;\)]*)(?:;\s*([^;\)]*))?(?:;\s*([^;\)]*))?\) like Gecko/u', $ua, $match)) {
  757. if (preg_match("/^[A-Z]+$/", $match[1]) && isset($match[2])) {
  758. $this->data->device->manufacturer = $match[1];
  759. $this->data->device->model = $match[2];
  760. } else {
  761. $this->data->device->model = $match[1];
  762. }
  763. $this->data->device->identified |= Constants\Id::PATTERN;
  764. $device = Data\DeviceModels::identify('wp', $this->data->device->model);
  765. if ($device->identified) {
  766. $device->identified |= $this->data->device->identified;
  767. $this->data->device = $device;
  768. }
  769. }
  770. /* Desktop mode of WP 7 */
  771. if (preg_match('/XBLWP7; ZuneWP7; ([^\)]+)\)/u', $ua, $match)) {
  772. $this->data->device->model = $match[1];
  773. $this->data->device->identified |= Constants\Id::PATTERN;
  774. $device = Data\DeviceModels::identify('wp', $match[1]);
  775. if ($device->identified) {
  776. $device->identified |= $this->data->device->identified;
  777. $this->data->device = $device;
  778. }
  779. }
  780. /* Desktop mode of WP 8.0 and 8.1 Update (buggy version) */
  781. if (preg_match('/Touch; WPDesktop;\s*([^;\)]*)(?:;\s*([^;\)]*))?(?:;\s*([^;\)]*))?\)/u', $ua, $match)) {
  782. if (preg_match("/^[A-Z]+$/", $match[1]) && isset($match[2])) {
  783. $this->data->device->manufacturer = $match[1];
  784. $this->data->device->model = $match[2];
  785. } else {
  786. $this->data->device->model = $match[1];
  787. }
  788. $this->data->device->identified |= Constants\Id::PATTERN;
  789. $device = Data\DeviceModels::identify('wp', $this->data->device->model);
  790. if ($device->identified) {
  791. $device->identified |= $this->data->device->identified;
  792. $this->data->device = $device;
  793. }
  794. }
  795. if (isset($this->data->device->manufacturer) && isset($this->data->device->model)) {
  796. if ($this->data->device->manufacturer == 'ARM' && $this->data->device->model == 'Touch') {
  797. $this->data->device->manufacturer = null;
  798. $this->data->device->model = null;
  799. $this->data->device->identified = Constants\Id::NONE;
  800. }
  801. if ($this->data->device->model == 'XDeviceEmulator') {
  802. $this->data->device->manufacturer = null;
  803. $this->data->device->model = null;
  804. $this->data->device->type = Constants\DeviceType::EMULATOR;
  805. $this->data->device->identified |= Constants\Id::MATCH_UA;
  806. }
  807. }
  808. }
  809. } elseif (preg_match('/WMPRO/u', $ua)) {
  810. $this->data->os->name = 'Windows Mobile';
  811. $this->data->device->type = Constants\DeviceType::MOBILE;
  812. }
  813. }
  814. private function detectWindowsOemManufacturer($ua)
  815. {
  816. $manufacturers = [
  817. 'MAAR' => 'Acer',
  818. 'ASJB' => 'Asus',
  819. 'ASU2' => 'Asus',
  820. 'MAAU' => 'Asus',
  821. 'NP06' => 'Asus',
  822. 'NP07' => 'Asus',
  823. 'NP08' => 'Asus',
  824. 'NP09' => 'Asus',
  825. 'CMNTDF' => 'Compaq',
  826. 'CPDTDF' => 'Compaq',
  827. 'CPNTDF' => 'Compaq',
  828. 'MDDR' => 'Dell',
  829. 'MDDC' => 'Dell',
  830. 'MDDS' => 'Dell',
  831. 'FSJB' => 'Fujitsu',
  832. 'MAFS' => 'Fujitsu',
  833. 'MAGW' => 'Gateway',
  834. 'HPCMHP' => 'HP',
  835. 'HPDTDF' => 'HP',
  836. 'HPNTDF' => 'HP',
  837. 'MANM' => 'Hyrican',
  838. 'LCJB' => 'Lenovo',
  839. 'LEN2' => 'Lenovo',
  840. 'MALC' => 'Lenovo',
  841. 'MALE' => 'Lenovo',
  842. 'MALN' => 'Lenovo',
  843. 'MAMD' => 'Medion',
  844. 'MAMI' => 'MSI',
  845. 'MAM3' => 'MSI',
  846. 'MASM' => 'Samsung',
  847. 'SMJB' => 'Samsung',
  848. 'MASA' => 'Sony',
  849. 'MASE' => 'Sony',
  850. 'MASP' => 'Sony',
  851. 'MATB' => 'Toshiba',
  852. 'MATM' => 'Toshiba',
  853. 'MATP' => 'Toshiba',
  854. 'TAJB' => 'Toshiba',
  855. 'TNJB' => 'Toshiba',
  856. ];
  857. $keys = array_keys($manufacturers);
  858. if (preg_match('/; (' . implode('|', $keys) . ')(?:JS)?[\);]/u', $ua, $match)) {
  859. $this->data->device->manufacturer = $manufacturers[$match[1]];
  860. $this->data->device->hidden = true;
  861. $this->data->device->identified |= Constants\Id::INFER;
  862. }
  863. }
  864. /* Jolla Sailfish */
  865. private function detectSailfish($ua)
  866. {
  867. if (preg_match('/Sailfish;/u', $ua)) {
  868. $this->data->os->name = 'Sailfish';
  869. $this->data->os->version = null;
  870. if (preg_match('/Jolla;/u', $ua)) {
  871. $this->data->device->manufacturer = 'Jolla';
  872. }
  873. if (preg_match('/Mobile/u', $ua)) {
  874. $this->data->device->model = 'Phone';
  875. $this->data->device->type = Constants\DeviceType::MOBILE;
  876. $this->data->device->identified = Constants\Id::PATTERN;
  877. }
  878. if (preg_match('/Tablet/u', $ua)) {
  879. $this->data->device->model = 'Tablet';
  880. $this->data->device->type = Constants\DeviceType::TABLET;
  881. $this->data->device->identified = Constants\Id::PATTERN;
  882. }
  883. }
  884. }
  885. /* Bada */
  886. private function detectBada($ua)
  887. {
  888. if (preg_match('/[b|B]ada/u', $ua)) {
  889. $this->data->os->name = 'Bada';
  890. if (preg_match('/[b|B]ada[\/ ]([0-9.]*)/u', $ua, $match)) {
  891. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  892. }
  893. $this->data->device->type = Constants\DeviceType::MOBILE;
  894. if (preg_match('/\(([^;]+); ([^\/]+)\//u', $ua, $match)) {
  895. if ($match[1] != 'Bada') {
  896. $this->data->device->manufacturer = $match[1];
  897. $this->data->device->model = $match[2];
  898. $this->data->device->identified = Constants\Id::PATTERN;
  899. $device = Data\DeviceModels::identify('bada', $match[2]);
  900. if ($device->identified) {
  901. $device->identified |= $this->data->device->identified;
  902. $this->data->device = $device;
  903. }
  904. }
  905. }
  906. }
  907. }
  908. /* Tizen */
  909. private function detectTizen($ua)
  910. {
  911. if (preg_match('/Tizen/u', $ua)) {
  912. $this->data->os->name = 'Tizen';
  913. if (preg_match('/Tizen[\/ ]?([0-9.]*[0-9])/u', $ua, $match)) {
  914. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  915. }
  916. if (preg_match('/\(([^;]+); ([^\/]+)\//u', $ua, $match)) {
  917. $falsepositive = false;
  918. if (strtoupper($match[1]) == 'SMART-TV') {
  919. $falsepositive = true;
  920. }
  921. if ($match[1] == 'TV') {
  922. $falsepositive = true;
  923. }
  924. if ($match[1] == 'Linux') {
  925. $falsepositive = true;
  926. }
  927. if ($match[1] == 'Tizen') {
  928. $falsepositive = true;
  929. }
  930. if (!$falsepositive) {
  931. $this->data->device->manufacturer = $match[1];
  932. $this->data->device->model = $match[2];
  933. $this->data->device->identified = Constants\Id::PATTERN;
  934. $device = Data\DeviceModels::identify('tizen', $match[2]);
  935. if ($device->identified) {
  936. $device->identified |= $this->data->device->identified;
  937. $this->data->device = $device;
  938. }
  939. }
  940. }
  941. if (preg_match('/\s*([^;]+);\s+([^;\)]+)\)/u', $ua, $match)) {
  942. $falsepositive = false;
  943. if ($match[1] == 'U') {
  944. $falsepositive = true;
  945. }
  946. if (substr($match[2], 0, 5) == 'Tizen') {
  947. $falsepositive = true;
  948. }
  949. if (substr($match[2], 0, 11) == 'AppleWebKit') {
  950. $falsepositive = true;
  951. }
  952. if (preg_match("/^[a-z]{2,2}(?:\-[a-z]{2,2})?$/", $match[2])) {
  953. $falsepositive = true;
  954. }
  955. if (!$falsepositive) {
  956. $this->data->device->model = $match[2];
  957. $this->data->device->identified = Constants\Id::PATTERN;
  958. $device = Data\DeviceModels::identify('tizen', $match[2]);
  959. if ($device->identified) {
  960. $device->identified |= $this->data->device->identified;
  961. $this->data->device = $device;
  962. }
  963. }
  964. }
  965. if (!$this->data->device->type && preg_match('/Mobile/iu', $ua, $match)) {
  966. $this->data->device->type = Constants\DeviceType::MOBILE;
  967. }
  968. if (preg_match('/\((SMART[ -])?TV;/iu', $ua, $match)) {
  969. $this->data->device->type = Constants\DeviceType::TELEVISION;
  970. $this->data->device->manufacturer = 'Samsung';
  971. $this->data->device->series = 'Smart TV';
  972. $this->data->device->identified = Constants\Id::PATTERN;
  973. }
  974. if (preg_match('/(?:Samsung|Tizen ?)Browser\/([0-9.]*)/u', $ua, $match)) {
  975. $this->data->browser->name = "Samsung Browser";
  976. $this->data->browser->channel = null;
  977. $this->data->browser->stock = true;
  978. $this->data->browser->version = new Version([ 'value' => $match[1] ]);
  979. $this->data->browser->channel = null;
  980. }
  981. }
  982. if (preg_match('/Linux\; U\; Android [0-9.]+\; ko\-kr\; SAMSUNG\; (NX[0-9]+[^\)]]*)/u', $ua, $match)) {
  983. $this->data->os->name = 'Tizen';
  984. $this->data->os->version = null;
  985. $this->data->device->type = Constants\DeviceType::CAMERA;
  986. $this->data->device->manufacturer = 'Samsung';
  987. $this->data->device->model = $match[1];
  988. $this->data->device->identified = Constants\Id::PATTERN;
  989. }
  990. }
  991. /* Symbian */
  992. private function detectSymbian($ua)
  993. {
  994. if (!preg_match('/(EPOC|Series|Symbian|S60|UIQ)/ui', $ua)) {
  995. return;
  996. }
  997. /* EPOC */
  998. if (preg_match('/EPOC(?:32)?[;\-\)]/u', $ua, $match)) {
  999. $this->data->os->name = 'EPOC';
  1000. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1001. $this->data->device->type = Constants\DeviceType::PDA;
  1002. if (preg_match('/Crystal\/([0-9.]*)/u', $ua, $match)) {
  1003. $this->data->os->name = 'Series80';
  1004. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  1005. $this->data->os->family->version = new Version([ 'value' => $match[1] ]);
  1006. $this->data->device->type = Constants\DeviceType::MOBILE;
  1007. $this->data->device->manufacturer = 'Nokia';
  1008. $this->data->device->model = '9210';
  1009. $this->data->device->identified |= Constants\Id::PATTERN;
  1010. }
  1011. if (preg_match('/Nokia\/Series-9200/u', $ua)) {
  1012. $this->data->os->name = 'Series80';
  1013. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  1014. $this->data->device->type = Constants\DeviceType::MOBILE;
  1015. $this->data->device->manufacturer = 'Nokia';
  1016. $this->data->device->model = '9210i';
  1017. $this->data->device->identified |= Constants\Id::PATTERN;
  1018. }
  1019. }
  1020. /* Series 80 */
  1021. if (preg_match('/Series80\/([0-9.]*)/u', $ua, $match)) {
  1022. $this->data->os->name = 'Series80';
  1023. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1024. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1025. $this->data->device->type = Constants\DeviceType::MOBILE;
  1026. }
  1027. /* Series 60 */
  1028. if (preg_match('/Symbian\/3/u', $ua)) {
  1029. $this->data->os->name = 'Series60';
  1030. $this->data->os->version = new Version([ 'value' => '5.2' ]);
  1031. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1032. $this->data->device->type = Constants\DeviceType::MOBILE;
  1033. }
  1034. if (preg_match('/Series[ ]?60/u', $ua) || preg_match('/S60[V\/;]/u', $ua)) {
  1035. $this->data->os->name = 'Series60';
  1036. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1037. $this->data->device->type = Constants\DeviceType::MOBILE;
  1038. if (preg_match('/Series60\/([0-9.]*)/u', $ua, $match)) {
  1039. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1040. }
  1041. if (preg_match('/S60\/([0-9.]*)/u', $ua, $match)) {
  1042. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1043. }
  1044. if (preg_match('/S60V([0-9.]*)/u', $ua, $match)) {
  1045. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1046. }
  1047. }
  1048. /* UIQ */
  1049. if (preg_match('/UIQ\/([0-9.]*)/u', $ua, $match)) {
  1050. $this->data->os->name = 'UIQ';
  1051. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1052. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1053. $this->data->device->type = Constants\DeviceType::MOBILE;
  1054. }
  1055. /* Symbian */
  1056. if (preg_match('/Symbian/u', $ua)) {
  1057. $this->data->os->family = new Family([ 'name' => 'Symbian' ]);
  1058. if (preg_match('/SymbianOS\/([0-9.]*)/u', $ua, $match)) {
  1059. $this->data->os->family->version = new Version([ 'value' => $match[1] ]);
  1060. }
  1061. }
  1062. if ($this->data->os->isFamily('Symbian')) {
  1063. if (preg_match('/Nokia-?([^\/;\)\s]+)[\s|\/|;|\)]/u', $ua, $match)) {
  1064. if ($match[1] != 'Browser') {
  1065. $this->data->device->manufacturer = 'Nokia';
  1066. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1067. $this->data->device->identified |= Constants\Id::PATTERN;
  1068. }
  1069. }
  1070. if (preg_match('/Symbian(?:\/3)?; U; (?:Nokia)?([^;]+); [a-z][a-z](?:\-[a-z][a-z])?/u', $ua, $match)) {
  1071. $this->data->device->manufacturer = 'Nokia';
  1072. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1073. $this->data->device->identified |= Constants\Id::PATTERN;
  1074. }
  1075. if (preg_match('/Vertu([^\/;]+)[\/|;]/u', $ua, $match)) {
  1076. $this->data->device->manufacturer = 'Vertu';
  1077. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1078. $this->data->device->identified |= Constants\Id::PATTERN;
  1079. }
  1080. if (preg_match('/Samsung\/([^;]*);/u', $ua, $match)) {
  1081. $this->data->device->manufacturer = 'Samsung';
  1082. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1083. $this->data->device->identified |= Constants\Id::PATTERN;
  1084. }
  1085. if (isset($this->data->device->model)) {
  1086. $device = Data\DeviceModels::identify('symbian', $this->data->device->model);
  1087. if ($device->identified) {
  1088. $device->identified |= $this->data->device->identified;
  1089. $this->data->device = $device;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. private function detectNokiaOs($ua)
  1095. {
  1096. if (!preg_match('/(Series|MeeGo|Maemo|Geos)/ui', $ua)) {
  1097. return;
  1098. }
  1099. /* Series 40 */
  1100. if (preg_match('/Series40/u', $ua)) {
  1101. $this->data->os->name = 'Series40';
  1102. if (preg_match('/Nokia([^\/]+)\//u', $ua, $match)) {
  1103. $this->data->device->manufacturer = 'Nokia';
  1104. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1105. $this->data->device->identified |= Constants\Id::PATTERN;
  1106. }
  1107. if (isset($this->data->device->model)) {
  1108. $device = Data\DeviceModels::identify('s40', $this->data->device->model);
  1109. if ($device->identified) {
  1110. $device->identified |= $this->data->device->identified;
  1111. $this->data->device = $device;
  1112. }
  1113. }
  1114. if (isset($this->data->device->model)) {
  1115. $device = Data\DeviceModels::identify('asha', $this->data->device->model);
  1116. if ($device->identified) {
  1117. $device->identified |= $this->data->device->identified;
  1118. $this->data->os->name = 'Nokia Asha Platform';
  1119. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  1120. $this->data->device = $device;
  1121. }
  1122. if (preg_match('/java_runtime_version=Nokia_Asha_([0-9_]+);/u', $ua, $match)) {
  1123. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  1124. }
  1125. }
  1126. $this->data->device->type = Constants\DeviceType::MOBILE;
  1127. }
  1128. /* Series 30+ */
  1129. if (preg_match('/Series30Plus/u', $ua)) {
  1130. $this->data->os->name = 'Series30+';
  1131. if (preg_match('/Nokia([^\/]+)\//u', $ua, $match)) {
  1132. $this->data->device->manufacturer = 'Nokia';
  1133. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1134. $this->data->device->identified |= Constants\Id::PATTERN;
  1135. }
  1136. if (isset($this->data->device->model)) {
  1137. $device = Data\DeviceModels::identify('s30plus', $this->data->device->model);
  1138. if ($device->identified) {
  1139. $device->identified |= $this->data->device->identified;
  1140. $this->data->device = $device;
  1141. }
  1142. }
  1143. $this->data->device->type = Constants\DeviceType::MOBILE;
  1144. }
  1145. /* Meego */
  1146. if (preg_match('/MeeGo/u', $ua)) {
  1147. $this->data->os->name = 'MeeGo';
  1148. $this->data->device->type = Constants\DeviceType::MOBILE;
  1149. if (preg_match('/Nokia([^\);]+)\)/u', $ua, $match)) {
  1150. $this->data->device->manufacturer = 'Nokia';
  1151. $this->data->device->model = Data\DeviceModels::cleanup($match[1]);
  1152. $this->data->device->identified |= Constants\Id::PATTERN;
  1153. $this->data->device->generic = false;
  1154. }
  1155. }
  1156. /* Maemo */
  1157. if (preg_match('/Maemo/u', $ua)) {
  1158. $this->data->os->name = 'Maemo';
  1159. $this->data->device->type = Constants\DeviceType::MOBILE;
  1160. if (preg_match('/(N[0-9]+)/u', $ua, $match)) {
  1161. $this->data->device->manufacturer = 'Nokia';
  1162. $this->data->device->model = $match[1];
  1163. $this->data->device->identified |= Constants\Id::PATTERN;
  1164. $this->data->device->generic = false;
  1165. }
  1166. }
  1167. /* GEOS */
  1168. if (preg_match('/Geos ([0-9.]+)/u', $ua, $match)) {
  1169. $this->data->os->name = 'GEOS';
  1170. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1171. $this->data->device->type = Constants\DeviceType::MOBILE;
  1172. if (preg_match('/Nokia-([0-9]{4,4}[a-z]?)/u', $ua, $match)) {
  1173. $this->data->device->manufacturer = 'Nokia';
  1174. $this->data->device->model = $match[1];
  1175. $this->data->device->identified |= Constants\Id::PATTERN;
  1176. $this->data->device->generic = false;
  1177. }
  1178. }
  1179. }
  1180. /* WebOS */
  1181. private function detectWebos($ua)
  1182. {
  1183. if (preg_match('/(?:web|hpw)OS\/(?:HP webOS )?([0-9.]*)/u', $ua, $match)) {
  1184. $this->data->os->name = 'webOS';
  1185. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1186. $this->data->device->type = preg_match('/Tablet/iu', $ua) ? Constants\DeviceType::TABLET : Constants\DeviceType::MOBILE;
  1187. $this->data->device->generic = false;
  1188. }
  1189. if (preg_match('/(?:Spark|elite)\/fzz/u', $ua, $match) || preg_match('/webOSBrowser/u', $ua, $match)) {
  1190. $this->data->os->name = 'webOS';
  1191. $this->data->device->type = preg_match('/Tablet/iu', $ua) ? Constants\DeviceType::TABLET : Constants\DeviceType::MOBILE;
  1192. $this->data->device->generic = false;
  1193. }
  1194. if (preg_match('/ (Pre|Pixi|TouchPad|P160UN?A?)\/[0-9\.]+$/u', $ua, $match)) {
  1195. $this->data->os->name = 'webOS';
  1196. $this->data->device->type = $match[1] == 'TouchPad' ? Constants\DeviceType::TABLET : Constants\DeviceType::MOBILE;
  1197. $this->data->device->generic = false;
  1198. }
  1199. if ($this->data->isOs('webOS')) {
  1200. if (preg_match('/Pre\/1.0/u', $ua)) {
  1201. $this->data->device->manufacturer = 'Palm';
  1202. $this->data->device->model = 'Pre';
  1203. }
  1204. if (preg_match('/Pre\/1.1/u', $ua)) {
  1205. $this->data->device->manufacturer = 'Palm';
  1206. $this->data->device->model = 'Pre Plus';
  1207. }
  1208. if (preg_match('/Pre\/1.2/u', $ua)) {
  1209. $this->data->device->manufacturer = 'Palm';
  1210. $this->data->device->model = 'Pre 2';
  1211. }
  1212. if (preg_match('/Pre\/3.0/u', $ua)) {
  1213. $this->data->device->manufacturer = 'Palm';
  1214. $this->data->device->model = 'Pre 3';
  1215. }
  1216. if (preg_match('/Pixi\/1.0/u', $ua)) {
  1217. $this->data->device->manufacturer = 'Palm';
  1218. $this->data->device->model = 'Pixi';
  1219. }
  1220. if (preg_match('/Pixi\/1.1/u', $ua)) {
  1221. $this->data->device->manufacturer = 'Palm';
  1222. $this->data->device->model = 'Pixi Plus';
  1223. }
  1224. if (preg_match('/P160UN?A?\/1.0/u', $ua)) {
  1225. $this->data->device->manufacturer = 'HP';
  1226. $this->data->device->model = 'Veer';
  1227. }
  1228. if (preg_match('/TouchPad\/1.0/u', $ua)) {
  1229. $this->data->device->manufacturer = 'HP';
  1230. $this->data->device->model = 'TouchPad';
  1231. }
  1232. if (preg_match('/Emulator\//u', $ua) || preg_match('/Desktop\//u', $ua)) {
  1233. $this->data->device->type = Constants\DeviceType::EMULATOR;
  1234. $this->data->device->manufacturer = null;
  1235. $this->data->device->model = null;
  1236. }
  1237. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1238. }
  1239. }
  1240. /* BlackBerry */
  1241. private function detectBlackberry($ua)
  1242. {
  1243. /* BlackBerry OS */
  1244. if (preg_match('/RIM([0-9]{3,3})/u', $ua, $match)) {
  1245. $this->data->os->name = 'BlackBerry OS';
  1246. $this->data->device->manufacturer = 'RIM';
  1247. $this->data->device->model = $match[1];
  1248. $this->data->device->type = Constants\DeviceType::MOBILE;
  1249. $this->data->device->identified = Constants\Id::INFER;
  1250. }
  1251. if (preg_match('/BlackBerry/u', $ua) && !preg_match('/BlackBerry Runtime for Android Apps/u', $ua)) {
  1252. $this->data->os->name = 'BlackBerry OS';
  1253. $this->data->device->model = 'BlackBerry';
  1254. $this->data->device->manufacturer = 'RIM';
  1255. $this->data->device->type = Constants\DeviceType::MOBILE;
  1256. $this->data->device->identified = Constants\Id::INFER;
  1257. if (!preg_match('/Opera/u', $ua)) {
  1258. if (preg_match('/BlackBerry([0-9]+[ei]?)\/([0-9.]*)/u', $ua, $match)) {
  1259. $this->data->device->model = $match[1];
  1260. $this->data->os->version = new Version([ 'value' => $match[2], 'details' => 2 ]);
  1261. }
  1262. if (preg_match('/; BlackBerry ([0-9]*);/u', $ua, $match)) {
  1263. $this->data->device->model = $match[1];
  1264. }
  1265. if (preg_match('/; ([0-9]+)[^;\)]+\)/u', $ua, $match)) {
  1266. $this->data->device->model = $match[1];
  1267. }
  1268. if (preg_match('/Version\/([0-9.]*)/u', $ua, $match)) {
  1269. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1270. }
  1271. if (isset($this->data->os->version) && $this->data->os->version->toFloat() >= 10) {
  1272. $this->data->os->name = 'BlackBerry';
  1273. }
  1274. if ($this->data->device->model) {
  1275. $device = Data\DeviceModels::identify('blackberry', $this->data->device->model);
  1276. if ($device->identified) {
  1277. $device->identified |= $this->data->device->identified;
  1278. $this->data->device = $device;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. /* BlackBerry 10 */
  1284. if (preg_match('/\(BB(1[^;]+); ([^\)]+)\)/u', $ua, $match)) {
  1285. $this->data->os->name = 'BlackBerry';
  1286. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1287. $this->data->device->manufacturer = 'BlackBerry';
  1288. $this->data->device->model = $match[2];
  1289. if ($this->data->device->model == 'Kbd') {
  1290. $this->data->device->model = 'Q series or Passport';
  1291. }
  1292. if ($this->data->device->model == 'Touch') {
  1293. $this->data->device->model = 'A or Z series';
  1294. }
  1295. if ($this->data->device->model == 'STL100-2') {
  1296. $this->data->device->model = 'Z10';
  1297. }
  1298. $this->data->device->type = preg_match('/Mobile/u', $ua) ? Constants\DeviceType::MOBILE : Constants\DeviceType::TABLET;
  1299. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1300. if (preg_match('/Version\/([0-9.]+)/u', $ua, $match)) {
  1301. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1302. }
  1303. }
  1304. /* BlackBerry Tablet OS */
  1305. if (preg_match('/RIM Tablet OS ([0-9.]*)/u', $ua, $match)) {
  1306. $this->data->os->name = 'BlackBerry Tablet OS';
  1307. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1308. $this->data->device->manufacturer = 'RIM';
  1309. $this->data->device->model = 'BlackBerry PlayBook';
  1310. $this->data->device->type = Constants\DeviceType::TABLET;
  1311. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1312. } elseif (preg_match('/\(PlayBook;/u', $ua) && preg_match('/PlayBook Build\/([0-9.]*)/u', $ua, $match)) {
  1313. $this->data->os->name = 'BlackBerry Tablet OS';
  1314. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1315. $this->data->device->manufacturer = 'RIM';
  1316. $this->data->device->model = 'BlackBerry PlayBook';
  1317. $this->data->device->type = Constants\DeviceType::TABLET;
  1318. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1319. } elseif (preg_match('/PlayBook/u', $ua) && !preg_match('/Android/u', $ua)) {
  1320. if (preg_match('/Version\/([0-9.]*)/u', $ua, $match)) {
  1321. $this->data->os->name = 'BlackBerry Tablet OS';
  1322. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1323. $this->data->device->manufacturer = 'RIM';
  1324. $this->data->device->model = 'BlackBerry PlayBook';
  1325. $this->data->device->type = Constants\DeviceType::TABLET;
  1326. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1327. }
  1328. }
  1329. /* Internal versions of BlackBerry 10 running on the Playbook */
  1330. if ($this->data->isOs('BlackBerry Tablet OS', '>=', 10)) {
  1331. $this->data->os->name = 'BlackBerry';
  1332. }
  1333. }
  1334. /* Chrome OS */
  1335. private function detectChromeos($ua)
  1336. {
  1337. /* ChromeCast */
  1338. if (preg_match('/CrKey/u', $ua) && !preg_match('/Espial/u', $ua)) {
  1339. $this->data->device->manufacturer = 'Google';
  1340. $this->data->device->model = 'Chromecast';
  1341. $this->data->device->type = Constants\DeviceType::TELEVISION;
  1342. $this->data->device->identified |= Constants\Id::MATCH_UA;
  1343. $this->data->device->generic = false;
  1344. }
  1345. /* Chrome OS */
  1346. if (preg_match('/CrOS/u', $ua)) {
  1347. $this->data->os->name = 'Chrome OS';
  1348. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1349. }
  1350. }
  1351. /* Open TV */
  1352. private function detectOpenTV($ua)
  1353. {
  1354. if (preg_match('/OpenTV/ui', $ua, $match)) {
  1355. $this->data->device->type = Constants\DeviceType::TELEVISION;
  1356. $this->data->os->name = 'OpenTV';
  1357. $this->data->os->version = null;
  1358. if (preg_match('/OpenTV Build\/([0-9\.]+)/u', $ua, $match)) {
  1359. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1360. }
  1361. if (preg_match('/OpenTV ([0-9\.]+)/u', $ua, $match)) {
  1362. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1363. }
  1364. if (preg_match('/Opentv([0-9]+)/u', $ua, $match)) {
  1365. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1366. }
  1367. if (preg_match('/OTV([0-9\.]+)/u', $ua, $match)) {
  1368. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1369. }
  1370. }
  1371. }
  1372. /* Qtopia */
  1373. private function detectQtopia($ua)
  1374. {
  1375. if (preg_match('/Qtopia/u', $ua)) {
  1376. $this->data->os->name = 'Qtopia';
  1377. if (preg_match('/Qtopia\/([0-9.]+)/u', $ua, $match)) {
  1378. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1379. }
  1380. }
  1381. }
  1382. /* Unix */
  1383. private function detectUnix($ua)
  1384. {
  1385. if (!preg_match('/(UNIX|OSF|ULTRIX|HP-UX|SunOS|Solaris|AIX|IRIX|NEWS-OS|GENIX)/ui', $ua)) {
  1386. return;
  1387. }
  1388. /* Unix */
  1389. if (preg_match('/Unix/iu', $ua)) {
  1390. $this->data->os->name = 'Unix';
  1391. }
  1392. /* Unix System V */
  1393. if (preg_match('/(?:UNIX_System_V|UNIX_SV) ([0-9.]*)/u', $ua, $match)) {
  1394. $this->data->os->name = 'UNIX System V';
  1395. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1396. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1397. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1398. }
  1399. /* Digital Unix */
  1400. if (preg_match('/OSF1?[ _]/u', $ua)) {
  1401. $this->data->os->name = 'Digital Unix';
  1402. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1403. if (preg_match('/OSF1?[ _]V?([0-9.]*)/u', $ua, $match)) {
  1404. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1405. }
  1406. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1407. }
  1408. /* Digital ULTRIX */
  1409. if (preg_match('/ULTRIX/u', $ua)) {
  1410. $this->data->os->name = 'ULTRIX';
  1411. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1412. if (preg_match('/ULTRIX ([0-9.]*)/u', $ua, $match)) {
  1413. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1414. }
  1415. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1416. }
  1417. /* HP-UX */
  1418. if (preg_match('/HP-UX/u', $ua)) {
  1419. $this->data->os->name = 'HP-UX';
  1420. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1421. if (preg_match('/HP-UX [A-Z].0?([1-9][0-9.]*)/u', $ua, $match)) {
  1422. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1423. }
  1424. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1425. }
  1426. /* Solaris */
  1427. if (preg_match('/SunOS/u', $ua)) {
  1428. $this->data->os->name = 'Solaris';
  1429. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1430. if (preg_match('/SunOS ([1234]\.[0-9\.]+)/u', $ua, $match)) {
  1431. $this->data->os->name = 'SunOS';
  1432. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1433. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1434. if (preg_match('/SunOS 4\.1\.([1234])/u', $ua, $match)) {
  1435. $this->data->os->name = 'Solaris';
  1436. switch ($match[1]) {
  1437. case '1':
  1438. $this->data->os->version = new Version([ 'value' => '1.0' ]);
  1439. break;
  1440. case '2':
  1441. $this->data->os->version = new Version([ 'value' => '1.0.1' ]);
  1442. break;
  1443. case '3':
  1444. $this->data->os->version = new Version([ 'value' => '1.1' ]);
  1445. break;
  1446. case '4':
  1447. $this->data->os->version = new Version([ 'value' => '1.1.2' ]);
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. if (preg_match('/SunOS 5\.([123456](?:\.[0-9\.]*)?) /u', $ua, $match)) {
  1453. $this->data->os->version = new Version([ 'value' => '2.' . $match[1] ]);
  1454. } else if (preg_match('/SunOS 5\.([0-9\.]*)/u', $ua, $match)) {
  1455. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1456. }
  1457. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1458. }
  1459. if (preg_match('/Solaris(?: ([0-9\.]+))?;/u', $ua, $match)) {
  1460. $this->data->os->name = 'Solaris';
  1461. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1462. if (preg_match('/Solaris ([0-9\.]+);/u', $ua, $match)) {
  1463. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1464. }
  1465. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1466. }
  1467. /* AIX */
  1468. if (preg_match('/AIX/u', $ua)) {
  1469. $this->data->os->name = 'AIX';
  1470. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1471. if (preg_match('/AIX ([0-9.]*)/u', $ua, $match)) {
  1472. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1473. }
  1474. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1475. }
  1476. /* IRIX */
  1477. if (preg_match('/IRIX/u', $ua)) {
  1478. $this->data->os->name = 'IRIX';
  1479. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1480. if (preg_match('/IRIX ([0-9.]*)/u', $ua, $match)) {
  1481. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1482. }
  1483. if (preg_match('/IRIX;?(?:64|32) ([0-9.]*)/u', $ua, $match)) {
  1484. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1485. }
  1486. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1487. }
  1488. /* Sony NEWS OS */
  1489. if (preg_match('/NEWS-OS ([0-9\.]+)/u', $ua, $match)) {
  1490. $this->data->os->name = 'NEWS OS';
  1491. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1492. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1493. if (preg_match('/NEWS-OS [56]/u', $ua)) {
  1494. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1495. }
  1496. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1497. }
  1498. /* NEC EWS-UX */
  1499. if (preg_match('/EWS-UNIX rev ([0-9\.]+)/u', $ua, $match)) {
  1500. $this->data->os->name = 'EWS-UX';
  1501. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1502. $this->data->os->family = new Family([ 'name' => 'UNIX' ]);
  1503. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1504. }
  1505. /* National Semiconductors GENIX */
  1506. if (preg_match('/GENIX ([0-9\.]+)/u', $ua, $match)) {
  1507. $this->data->os->name = 'GENIX';
  1508. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1509. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1510. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1511. }
  1512. }
  1513. /* BSD */
  1514. private function detectBsd($ua)
  1515. {
  1516. if (!preg_match('/(BSD|DragonFly)/ui', $ua)) {
  1517. return;
  1518. }
  1519. if (preg_match('/X11/u', $ua)) {
  1520. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1521. }
  1522. /* BSD/OS */
  1523. if (preg_match('/BSD\/386/u', $ua)) {
  1524. $this->data->os->name = 'BSD/OS';
  1525. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1526. }
  1527. if (preg_match('/BSD\/OS/u', $ua)) {
  1528. $this->data->os->name = 'BSD/OS';
  1529. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1530. if (preg_match('/BSD\/OS ([0-9.]*)/u', $ua, $match)) {
  1531. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1532. }
  1533. }
  1534. /* FreeBSD */
  1535. if (preg_match('/FreeBSD/iu', $ua)) {
  1536. $this->data->os->name = 'FreeBSD';
  1537. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1538. if (preg_match('/FreeBSD[ -\/]?([0-9.]*)/iu', $ua, $match)) {
  1539. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1540. }
  1541. }
  1542. /* OpenBSD */
  1543. if (preg_match('/OpenBSD/iu', $ua)) {
  1544. $this->data->os->name = 'OpenBSD';
  1545. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1546. if (preg_match('/OpenBSD ?([0-9.]*)/iu', $ua, $match)) {
  1547. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1548. }
  1549. }
  1550. /* NetBSD */
  1551. if (preg_match('/NetBSD/iu', $ua)) {
  1552. $this->data->os->name = 'NetBSD';
  1553. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1554. if (preg_match('/NetBSD ?([0-9.]*)/iu', $ua, $match)) {
  1555. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1556. }
  1557. }
  1558. /* DragonFly */
  1559. if (preg_match('/DragonFly/iu', $ua)) {
  1560. $this->data->os->name = 'DragonFly BSD';
  1561. $this->data->os->family = new Family([ 'name' => 'BSD' ]);
  1562. }
  1563. }
  1564. /* Linux */
  1565. private function detectLinux($ua)
  1566. {
  1567. if (preg_match('/Linux/u', $ua)) {
  1568. $this->data->os->name = 'Linux';
  1569. if (preg_match('/X11/u', $ua)) {
  1570. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1571. }
  1572. if (preg_match('/Antergos Linux/u', $ua)) {
  1573. $this->data->os->name = 'Antergos Linux';
  1574. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1575. }
  1576. if (preg_match('/Arch ?Linux/u', $ua)) {
  1577. $this->data->os->name = 'Arch Linux';
  1578. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1579. }
  1580. if (preg_match('/Black Lab Linux/u', $ua)) {
  1581. $this->data->os->name = 'Black Lab Linux';
  1582. if (preg_match('/Black Lab Linux ([0-9\.]+)/u', $ua, $match)) {
  1583. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1584. }
  1585. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1586. }
  1587. if (preg_match('/CentOS/u', $ua)) {
  1588. $this->data->os->name = 'CentOS';
  1589. if (preg_match('/CentOS\/[0-9\.\-]+el([0-9_]+)/u', $ua, $match)) {
  1590. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  1591. }
  1592. if (preg_match('/CentOS Linux release ([0-9\.]+)/u', $ua, $match)) {
  1593. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1594. }
  1595. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1596. }
  1597. if (preg_match('/Debian/u', $ua)) {
  1598. $this->data->os->name = 'Debian';
  1599. if (preg_match('/Debian\/([0-9.]*)/iu', $ua, $match)) {
  1600. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1601. }
  1602. if (preg_match('/Debian GNU\/Linux ([0-9\.]+)/u', $ua, $match)) {
  1603. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1604. }
  1605. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1606. }
  1607. if (preg_match('/elementary OS/u', $ua)) {
  1608. $this->data->os->name = 'elementary OS';
  1609. if (preg_match('/elementary OS ([A-Za-z]+)/u', $ua, $match)) {
  1610. $this->data->os->version = new Version([ 'alias' => $match[1] ]);
  1611. }
  1612. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1613. }
  1614. if (preg_match('/Fedora/u', $ua)) {
  1615. $this->data->os->name = 'Fedora';
  1616. if (preg_match('/Fedora\/[0-9\.\-]+fc([0-9]+)/u', $ua, $match)) {
  1617. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  1618. }
  1619. if (preg_match('/Fedora release ([0-9\.]+)/u', $ua, $match)) {
  1620. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1621. }
  1622. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1623. }
  1624. if (preg_match('/Gentoo/u', $ua)) {
  1625. $this->data->os->name = 'Gentoo';
  1626. if (preg_match('/Gentoo Base System release ([0-9\.]+)/u', $ua, $match)) {
  1627. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1628. }
  1629. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1630. }
  1631. if (preg_match('/gNewSense/u', $ua)) {
  1632. $this->data->os->name = 'gNewSense';
  1633. if (preg_match('/gNewSense\/[^\(]+\(([0-9\.]+)/u', $ua, $match)) {
  1634. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1635. }
  1636. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1637. }
  1638. if (preg_match('/Kubuntu/u', $ua)) {
  1639. $this->data->os->name = 'Kubuntu';
  1640. if (preg_match('/Kubuntu[ \/]([0-9.]*)/iu', $ua, $match)) {
  1641. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1642. }
  1643. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1644. }
  1645. if (preg_match('/Linux Mint/u', $ua)) {
  1646. $this->data->os->name = 'Linux Mint';
  1647. if (preg_match('/Linux Mint ([0-9\.]+)/iu', $ua, $match)) {
  1648. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1649. }
  1650. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1651. }
  1652. if (preg_match('/Mandriva Linux/u', $ua)) {
  1653. $this->data->os->name = 'Mandriva';
  1654. if (preg_match('/Mandriva Linux\/[0-9\.\-]+mdv([0-9]+)/u', $ua, $match)) {
  1655. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1656. }
  1657. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1658. }
  1659. if (preg_match('/Mageia/u', $ua)) {
  1660. $this->data->os->name = 'Mageia';
  1661. if (preg_match('/Mageia\/[0-9\.\-]+mga([0-9]+)/u', $ua, $match)) {
  1662. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1663. }
  1664. if (preg_match('/Mageia ([0-9\.]+)/iu', $ua, $match)) {
  1665. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1666. }
  1667. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1668. }
  1669. if (preg_match('/Mandriva/u', $ua)) {
  1670. $this->data->os->name = 'Mandriva';
  1671. if (preg_match('/Mandriva\/[0-9\.\-]+mdv([0-9]+)/u', $ua, $match)) {
  1672. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1673. }
  1674. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1675. }
  1676. if (preg_match('/moonOS/u', $ua)) {
  1677. $this->data->os->name = 'moonOS';
  1678. if (preg_match('/moonOS\/([0-9.]+)/u', $ua, $match)) {
  1679. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1680. }
  1681. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1682. }
  1683. if (preg_match('/Red Hat/u', $ua)) {
  1684. $this->data->os->name = 'Red Hat';
  1685. if (preg_match('/Red Hat[^\/]*\/[0-9\.\-]+el([0-9_]+)/u', $ua, $match)) {
  1686. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  1687. }
  1688. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1689. }
  1690. if (preg_match('/Slackware/u', $ua)) {
  1691. $this->data->os->name = 'Slackware';
  1692. if (preg_match('/Slackware[ \/](1[0-9.]+)/u', $ua, $match)) {
  1693. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1694. }
  1695. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1696. }
  1697. if (preg_match('/SUSE/u', $ua)) {
  1698. $this->data->os->name = 'SUSE';
  1699. if (preg_match('/SUSE\/([0-9]\.[0-9]+)/u', $ua, $match)) {
  1700. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1701. }
  1702. if (preg_match('/openSUSE ([0-9\.]+)/iu', $ua, $match)) {
  1703. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1704. }
  1705. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1706. }
  1707. if (preg_match('/Turbolinux/u', $ua)) {
  1708. $this->data->os->name = 'Turbolinux';
  1709. if (preg_match('/Turbolinux\/([0-9]\.[0-9]+)/u', $ua, $match)) {
  1710. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1711. }
  1712. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1713. }
  1714. if (preg_match('/Ubuntu/u', $ua)) {
  1715. $this->data->os->name = 'Ubuntu';
  1716. if (preg_match('/Ubuntu\/([0-9.]*)/u', $ua, $match)) {
  1717. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1718. }
  1719. if (preg_match('/Ubuntu ([0-9\.]+)/iu', $ua, $match)) {
  1720. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => 2 ]);
  1721. }
  1722. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1723. }
  1724. if (preg_match('/《붉은별》\/([0-9.]*)/iu', $ua, $match)) {
  1725. $this->data->os->name = 'Red Star';
  1726. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1727. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1728. }
  1729. if (preg_match('/Fedora\/[0-9\.\-]+rs([0-9\.]+)/u', $ua, $match)) {
  1730. $this->data->os->name = 'Red Star';
  1731. $this->data->os->version = new Version([ 'value' => str_replace('_', '.', $match[1]) ]);
  1732. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1733. }
  1734. if (preg_match('/Linux\/X2\/R1/u', $ua)) {
  1735. $this->data->os->name = 'LiMo';
  1736. $this->data->device->type = Constants\DeviceType::MOBILE;
  1737. }
  1738. if (preg_match('/Linux\/SLP\/([0-9.]+)/u', $ua, $match)) {
  1739. $this->data->os->name = 'Linux SLP';
  1740. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1741. $this->data->device->type = Constants\DeviceType::MOBILE;
  1742. }
  1743. if (preg_match('/LinuxOS\//u', $ua) && preg_match('/Software\/R5/u', $ua)) {
  1744. $this->data->os->name = 'EZX Linux';
  1745. $this->data->device->type = Constants\DeviceType::MOBILE;
  1746. }
  1747. }
  1748. if (preg_match('/\(Ubuntu; (Mobile|Tablet)/u', $ua)) {
  1749. $this->data->os->name = 'Ubuntu Touch';
  1750. if (preg_match('/\(Ubuntu; Mobile/u', $ua)) {
  1751. $this->data->device->type = Constants\DeviceType::MOBILE;
  1752. }
  1753. if (preg_match('/\(Ubuntu; Tablet/u', $ua)) {
  1754. $this->data->device->type = Constants\DeviceType::TABLET;
  1755. }
  1756. }
  1757. if (preg_match('/(?:\(|; )Ubuntu ([0-9.]+) like Android/u', $ua, $match)) {
  1758. $this->data->os->name = 'Ubuntu Touch';
  1759. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1760. $this->data->device->type = Constants\DeviceType::MOBILE;
  1761. }
  1762. if (preg_match('/Lindows ([0-9.]+)/u', $ua, $match)) {
  1763. $this->data->os->name = 'Lindows';
  1764. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1765. $this->data->device->type = Constants\DeviceType::DESKTOP;
  1766. }
  1767. }
  1768. /* Brew */
  1769. private function detectBrew($ua)
  1770. {
  1771. if (preg_match('/REX; U/ui', $ua) || preg_match('/REXL4/ui', $ua)) {
  1772. $this->data->os->name = 'REX';
  1773. $this->data->device->type = Constants\DeviceType::MOBILE;
  1774. if (preg_match('/REX; U; [^;]+; ([^;]+); ([^;\/]+)[^;]*; NetFront/u', $ua, $match)) {
  1775. $this->data->device->manufacturer = Data\Manufacturers::identify(Constants\DeviceType::MOBILE, $match[1]);
  1776. $this->data->device->model = $match[2];
  1777. $this->data->device->identified = Constants\Id::PATTERN;
  1778. $device = Data\DeviceModels::identify('brew', $match[2]);
  1779. if ($device->identified) {
  1780. $device->identified |= $this->data->device->identified;
  1781. $this->data->device = $device;
  1782. }
  1783. }
  1784. }
  1785. if (preg_match('/[\(\s\-;]BREW[\s\/\-;]/ui', $ua) || preg_match('/BMP( [0-9.]*)?; U/u', $ua) || preg_match('/B(?:rew)?MP\/([0-9.]*)/u', $ua)) {
  1786. $this->data->os->name = 'Brew';
  1787. if (preg_match('/BREW MP/iu', $ua) || preg_match('/B(rew)?MP/iu', $ua)) {
  1788. $this->data->os->name = 'Brew MP';
  1789. }
  1790. if (preg_match('/; Brew ([0-9.]+);/iu', $ua, $match)) {
  1791. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1792. } elseif (preg_match('/BREW; U; ([0-9.]+)/iu', $ua, $match)) {
  1793. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1794. } elseif (preg_match('/[\(;]BREW[\/ ]([0-9.]+)/iu', $ua, $match)) {
  1795. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1796. } elseif (preg_match('/BREW MP ([0-9.]*)/iu', $ua, $match)) {
  1797. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1798. } elseif (preg_match('/BMP ([0-9.]*); U/iu', $ua, $match)) {
  1799. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1800. } elseif (preg_match('/B(?:rew)?MP\/([0-9.]*)/iu', $ua, $match)) {
  1801. $this->data->os->version = new Version([ 'value' => $match[1] ]);
  1802. }
  1803. $this->data->device->type = Constants\DeviceType::MOBILE;
  1804. if (preg_match('/(?:Brew MP|BREW|BMP) [^;]+; U; [^;]+; ([^;]+); NetFront[^\)]+\) [^\s]+ ([^\s]+)/u', $ua, $match)) {
  1805. $this->data->device->manufacturer = Data\Manufacturers::identify(Constants\DeviceType::MOBILE, $match[1]);
  1806. $this->data->device->model = $match[2];
  1807. $this->data->device->identified = Constants\Id::PATTERN;
  1808. $device = Data\DeviceModels::identify('brew', $match[2]);
  1809. if ($device->identified) {
  1810. $device->identified |= $this->data->device->identified;
  1811. $this->data->device = $device;
  1812. }
  1813. }
  1814. if (preg_match('/\(([^;]+);U;REX\/[^;]+;BREW\/[^;]+;(?:.*;)?[0-9]+\*[0-9]+(?:;CTC\/2.0)?\)/u', $ua, $match)) {
  1815. $this->data->device->model = $match[1];
  1816. $this->data->device->identified = Constants\Id::PATTERN;
  1817. $device = Data\DeviceModels::identify('brew', $match[1]);
  1818. if ($device->identified) {
  1819. $device->identified |= $this->data->device->identified;
  1820. $this->data->device = $device;
  1821. }
  1822. }
  1823. if (preg_match('/\(BREW [^;]+; U; [^;]+; [^;]+; ([^;]+); (Polaris|Netfront)\/[0-9\.]+\/(WAP|AMB|INT)\)/ui', $ua, $match)) {
  1824. $this->data->device->model = $match[1];
  1825. $this->data->device->identified = Constants\Id::PATTERN;
  1826. $device = Data\DeviceModels::identify('brew', $match[1]);
  1827. if ($device->identified) {
  1828. $device->identified |= $this->data->device->identified;
  1829. $this->data->device = $device;
  1830. }
  1831. }
  1832. if (preg_match('/\(BREW [^;]+; U; [^;]+; [^;]+; Opera Mobi; Presto\/[0-9\.]+\/(?:WAP|AMB|INT)\) ([^\/]+) [^\/]+\//ui', $ua, $match)) {
  1833. $this->data->device->model = $match[1];
  1834. $this->data->device->identified = Constants\Id::PATTERN;
  1835. $device = Data\DeviceModels::identify('brew', $match[1]);
  1836. if ($device->identified) {
  1837. $device->identified |= $this->data->device->identified;
  1838. $this->data->device = $device;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. /* Remaining operating systems */
  1844. private function detectRemainingOperatingSystems($ua)
  1845. {
  1846. if (!preg_match('/(BeOS|Haiku|AmigaOS|MorphOS|AROS|VMS|RISC|Joli|OS\/2|Inferno|Syllable|Grid|MTK|MRE|MAUI|Nucleus|QNX|VRE|SpreadTrum|ThreadX)/ui', $ua)) {
  1847. return;
  1848. }
  1849. $patterns = [
  1850. [ 'name' => 'BeOS', 'regexp' => [ '/BeOS/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1851. [ 'name' => 'Haiku', 'regexp' => [ '/Haiku/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1852. [ 'name' => 'AmigaOS', 'regexp' => [ '/AmigaOS ?([0-9.]+)/iu', '/AmigaOS/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1853. [ 'name' => 'MorphOS', 'regexp' => [ '/MorphOS(?: ([0-9.]*))?/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1854. [ 'name' => 'AROS', 'regexp' => [ '/AROS/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1855. [ 'name' => 'OpenVMS', 'regexp' => [ '/OpenVMS V([0-9.]+)/iu', '/OpenVMS/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1856. [ 'name' => 'RISC OS', 'regexp' => [ '/RISC OS(?:-NC)? ([0-9.]*)/iu', '/RISC OS/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1857. [ 'name' => 'Joli OS', 'regexp' => [ '/Joli OS\/([0-9.]*)/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1858. [ 'name' => 'OS/2', 'regexp' => [ '/OS\/2;(?: (?:U; )?Warp ([0-9.]*))?/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1859. [ 'name' => 'Inferno', 'regexp' => [ '/Inferno/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1860. [ 'name' => 'Syllable', 'regexp' => [ '/Syllable/iu' ], 'type' => Constants\DeviceType::DESKTOP ],
  1861. [ 'name' => 'Grid OS', 'regexp' => [ '/Grid OS ([0-9.]*)/iu' ], 'type' => Constants\DeviceType::TABLET ],
  1862. [ 'name' => 'MRE', 'regexp' => [ '/\(MTK;/iu', '/\/MTK /iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1863. [ 'name' => 'MRE', 'regexp' => [ '/MRE\\\\/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1864. [ 'name' => 'MRE', 'regexp' => [ '/MAUI[-_ ](?:Browser|Runtime)/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1865. [ 'name' => 'MRE', 'regexp' => [ '/Browser\/MAUI/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1866. [ 'name' => 'MRE', 'regexp' => [ '/Nucleus RTOS\//iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1867. [ 'name' => 'MRE', 'regexp' => [ '/\/Nucleus/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1868. [ 'name' => 'MRE', 'regexp' => [ '/Nucleus\//iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1869. [ 'name' => 'QNX', 'regexp' => [ '/QNX/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1870. [ 'name' => 'VRE', 'regexp' => [ '/\(VRE;/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1871. [ 'name' => 'SpreadTrum', 'regexp' => [ '/\(SpreadTrum;/iu' ], 'type' => Constants\DeviceType::MOBILE ],
  1872. [ 'name' => 'ThreadX', 'regexp' => [ '/ThreadX(?:_OS)?\/([0-9.]*)/iu' ] ],
  1873. ];
  1874. $count = count($patterns);
  1875. for ($b = 0; $b < $count; $b++) {
  1876. for ($r = 0; $r < count($patterns[$b]['regexp']); $r++) {
  1877. if (preg_match($patterns[$b]['regexp'][$r], $ua, $match)) {
  1878. $this->data->os->name = $patterns[$b]['name'];
  1879. if (isset($match[1]) && $match[1]) {
  1880. $this->data->os->version = new Version([ 'value' => $match[1], 'details' => isset($patterns[$b]['details']) ? $patterns[$b]['details'] : null ]);
  1881. } else {
  1882. $this->data->os->version = null;
  1883. }
  1884. if (isset($patterns[$b]['type'])) {
  1885. $this->data->device->type = $patterns[$b]['type'];
  1886. }
  1887. break;
  1888. }
  1889. }
  1890. }
  1891. }
  1892. }