PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/h-source/Application/Include/hardware.php

https://gitlab.com/7slayer/h-node
PHP | 567 lines | 444 code | 102 blank | 21 comment | 10 complexity | b9ff8fff4aef44a0a93fe2f4a2e36af0 MD5 | raw file
  1. <?php
  2. // h-source, a web software to build a community of people that want to share their hardware information.
  3. // Copyright (C) 2010 Antonio Gallo (h-source-copyright.txt)
  4. //
  5. // This file is part of h-source
  6. //
  7. // h-source is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // h-source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with h-source. If not, see <http://www.gnu.org/licenses/>.
  19. if (!defined('EG')) die('Direct access not allowed!');
  20. function translate($string)
  21. {
  22. return Hardware::translate($string);
  23. }
  24. function translate_and_gtext($string)
  25. {
  26. return gtext(translate($string));
  27. }
  28. class Hardware
  29. {
  30. public static $translations = array(
  31. "amd64" => 'x86-64/amd64',
  32. "PC-Card" => 'PCMCIA/PC-Card',
  33. "works_with_3D" => "works with 3D acceleration",
  34. "works_without_3D" => "works, but without 3D acceleration",
  35. "does_not_work" => "it does not work",
  36. "can-be-installed" => "can be installed",
  37. "pcmcia-controller" => "PCMCIA Controller",
  38. "usb-controller" => "USB Controller",
  39. "firewire-controller" => "Firewire Controller",
  40. "heci-controller" => "HECI Controller",
  41. );
  42. public static $regExpressions = array(
  43. "kernel" => "/^[a-zA-Z0-9\-\_\.\+\s\(\)\,]+$/",
  44. "driver" => "/^[a-zA-Z0-9\-\_\.\+\s\/\,\:\;\(\)\[\]]+$/",
  45. "vendorid_productid" => "/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/",
  46. "model" => "/^[a-zA-Z0-9\-\_\.\+\s\(\)\@\[\]\/\,\']+$/",
  47. );
  48. public static function translate($string)
  49. {
  50. if (array_key_exists($string,self::$translations))
  51. {
  52. return self::$translations[$string];
  53. }
  54. return $string;
  55. }
  56. //classId => controller
  57. public static $deviceClasses = array(
  58. '0403' => 'soundcards',
  59. '0280' => 'wifi',
  60. '0300' => 'videocards',
  61. '0200' => 'ethernetcards',
  62. '0400' => 'acquisitioncards',
  63. '0401' => 'acquisitioncards',
  64. '0480' => 'acquisitioncards',
  65. '0805' => 'sdcardreaders',
  66. '0703' => 'modems',
  67. '0104' => 'raidadapters',
  68. '0c00' => 'hostcontrollers',
  69. '0c03' => 'hostcontrollers',
  70. '0780' => 'hostcontrollers',
  71. '0607' => 'hostcontrollers',
  72. '0e00' => 'raidadapters',
  73. );
  74. public static $icons = array(
  75. 'notebook' => 'H2O/computer-laptop_22.png',
  76. 'wifi' => 'H2O/network-wireless_22.png',
  77. 'videocard' => 'Crystal/1282042976_hardware.png',
  78. 'printer' => 'H2O/printer_22.png',
  79. 'scanner' => 'H2O/scanner_22.png',
  80. '3G-card' => 'Crystal/usb_22.png',
  81. 'soundcard' => 'H2O/audio-card_22.png',
  82. 'webcam' => 'H2O/camera-web_22.png',
  83. 'bluetooth' => 'H2O/preferences-system-bluetooth-22.png',
  84. 'acquisition-card' => 'Crystal/cam_mount-22.png',
  85. 'fingerprint-reader' => 'fingerprint_icon-22.png',
  86. 'ethernet-card' => 'H2O/network-wired_22.png',
  87. 'sd-card-reader' => 'H2O/media-flash-sd-mmc_22.png',
  88. 'modem' => 'Crystal/modem_22.png',
  89. 'RAID-adapter' => 'Crystal/1282042976_hardware.png',
  90. 'host-controller' => 'Crystal/1282042976_hardware.png',
  91. );
  92. public static $typeToController = array(
  93. 'notebook' => 'notebooks',
  94. 'wifi' => 'wifi',
  95. 'videocard' => 'videocards',
  96. 'printer' => 'printers',
  97. 'scanner' => 'scanners',
  98. '3G-card' => 'threegcards',
  99. 'soundcard' => 'soundcards',
  100. 'webcam' => 'webcams',
  101. 'bluetooth' => 'bluetooth',
  102. 'acquisition-card' => 'acquisitioncards',
  103. 'fingerprint-reader' => 'fingerprintreaders',
  104. 'ethernet-card' => 'ethernetcards',
  105. 'sd-card-reader' => 'sdcardreaders',
  106. 'modem' => 'modems',
  107. 'RAID-adapter' => 'raidadapters',
  108. 'host-controller' => 'hostcontrollers',
  109. );
  110. public static $typeToWorksField = array(
  111. 'notebook' => 'compatibility',
  112. 'wifi' => 'wifi_works',
  113. 'videocard' => 'video_card_works',
  114. 'printer' => 'compatibility',
  115. 'scanner' => 'compatibility',
  116. '3G-card' => 'wifi_works',
  117. 'soundcard' => 'sound_card_works',
  118. 'webcam' => 'webcam_works',
  119. 'bluetooth' => 'bluetooth_works',
  120. 'acquisition-card' => 'compatibility',
  121. 'fingerprint-reader' => 'fingerprint_works',
  122. 'ethernet-card' => 'ethernet_card_works',
  123. 'sd-card-reader' => 'sd_card_works',
  124. 'modem' => 'compatibility',
  125. 'RAID-adapter' => 'compatibility',
  126. 'host-controller' => 'compatibility',
  127. );
  128. public static function getTypes()
  129. {
  130. return implode(',',array_keys(self::$typeToController));
  131. }
  132. public static function getControllerFromType($type)
  133. {
  134. if (array_key_exists($type,self::$typeToController))
  135. {
  136. return self::$typeToController[$type];
  137. }
  138. return null;
  139. }
  140. public static function getWorksFieldFromType($type)
  141. {
  142. if (array_key_exists($type,self::$typeToWorksField))
  143. {
  144. return self::$typeToWorksField[$type];
  145. }
  146. return null;
  147. }
  148. //get the type from the controller
  149. public static function getTypeFromController($controller)
  150. {
  151. $temp = array_flip(self::$typeToController);
  152. if (array_key_exists($controller,$temp))
  153. {
  154. return $temp[$controller];
  155. }
  156. return null;
  157. }
  158. public static function getTypeFromClass($class)
  159. {
  160. if (array_key_exists($class,self::$deviceClasses))
  161. {
  162. return self::getTypeFromController(self::$deviceClasses[$class]);
  163. }
  164. return null;
  165. }
  166. public static function getIconFromType($type)
  167. {
  168. if (array_key_exists($type,self::$icons))
  169. {
  170. return Url::getRoot()."Public/Img/".self::$icons[$type];
  171. }
  172. return null;
  173. }
  174. public static function getIconFromController($controller)
  175. {
  176. if ($type = self::getTypeFromController($controller))
  177. {
  178. return self::getIconFromType($type);
  179. }
  180. return null;
  181. }
  182. public static function getIconFromClass($class)
  183. {
  184. if (array_key_exists($class,self::$deviceClasses))
  185. {
  186. return self::getIconFromController(self::$deviceClasses[$class]);
  187. }
  188. return null;
  189. }
  190. //get the list of the allowed years of commercialization
  191. public static function getCommYears()
  192. {
  193. $currentYear = (int)date("Y");
  194. $allowed = 'not-specified';
  195. for ($i=$currentYear;$i>1991;$i--)
  196. {
  197. $allowed .= ",$i";
  198. }
  199. return $allowed;
  200. }
  201. public static $trackSelect = 'not-specified,no,yes';
  202. }
  203. class Printer extends Hardware
  204. {
  205. public static $compatibility = array(
  206. "A-Full" => "A-Full",
  207. "B-Partial" => "B-Partial",
  208. "C-None" => "C-None",
  209. );
  210. public static $interface = "not-specified,USB,Serial,Parallel,Firewire,SCSI,Ethernet";
  211. public static $subtype = "not-specified,laser,inkjet,other";
  212. public static function compatibilityList()
  213. {
  214. return implode(',',array_values(self::$compatibility));
  215. }
  216. }
  217. class Wifi extends Hardware
  218. {
  219. public static $interface = array(
  220. "not-specified" => "not-specified",
  221. "USB" => "USB",
  222. "PCI" => "PCI",
  223. "PCI-E" => "PCI-E",
  224. "mini-PCI" => "mini-PCI",
  225. "mini-PCI-E" => "mini-PCI-E",
  226. "ExpressCard" => "ExpressCard",
  227. "Ethernet" => "Ethernet",
  228. "PCMCIA/PC-Card" => "PC-Card",
  229. );
  230. public static $interfaceReverse = array(
  231. "not-specified" => "not-specified",
  232. "USB" => "USB",
  233. "PCI" => "PCI",
  234. "PCI-E" => "PCI-E",
  235. "mini-PCI" => "mini-PCI",
  236. "mini-PCI-E" => "mini-PCI-E",
  237. "ExpressCard" => "ExpressCard",
  238. "Ethernet" => "Ethernet",
  239. "PC-Card" => "PCMCIA/PC-Card",
  240. );
  241. public static $wifiSelect = 'yes,no';
  242. public static function interfaceList()
  243. {
  244. return implode(',',array_values(self::$interface));
  245. }
  246. }
  247. class Videocard extends Hardware
  248. {
  249. public static $videoSelect = array(
  250. "works with 3D acceleration" => "works_with_3D",
  251. "works, but without 3D acceleration" => "works_without_3D",
  252. "it does not work" => "does_not_work",
  253. );
  254. public static $videoReverse = array(
  255. "works_with_3D" => "works with 3D acceleration",
  256. "works_without_3D" => "works, but without 3D acceleration",
  257. "does_not_work" => "it does not work",
  258. );
  259. public static $interface = "not-specified,PCI,AGP,PCI-E,ISA,MCA,VLB";
  260. public static function videoList()
  261. {
  262. return implode(',',array_values(self::$videoSelect));
  263. }
  264. }
  265. class Notebooks extends Hardware
  266. {
  267. public static $vendors = array(
  268. "Acer" => "Acer",
  269. "Apple" => "Apple",
  270. "Asus" => "Asus",
  271. "BenQ" => "BenQ",
  272. "Blue Light" => "Blue-Light",
  273. "CLEVO CO." => "CLEVO-CO",
  274. "Compal Electronics" => "Compal-Electronics",
  275. "COMPAQ" => "COMPAQ",
  276. "Dell" => "Dell",
  277. "emachines" => "emachines",
  278. "FUJITSU" => "FUJITSU",
  279. "Garlach44" => "Garlach44",
  280. "Gateway" => "Gateway",
  281. "Google" => "Google",
  282. "Hewlett Packard" => "Hewlett-Packard",
  283. "IBM" => "IBM",
  284. "Lanix" => "Lanix",
  285. "Lemote" => "Lemote",
  286. "Lenovo" => "Lenovo",
  287. "LG" => "LG",
  288. "msi" => "msi",
  289. "Olimex" => "Olimex",
  290. "One Laptop per Child (Non-Profit)" => "One-Laptop-per-Child-Non-Profit",
  291. "Openpandora Ltd." => "Openpandora-Ltd",
  292. "Oracle" => "Oracle",
  293. "Packard Bell" => "Packard-Bell",
  294. "Philco" => "Philco",
  295. "Philips" => "Philips",
  296. "Panasonic" => "Panasonic",
  297. "SAMSUNG" => "SAMSUNG",
  298. "Sony" => "Sony",
  299. "System76" => "System76",
  300. "Thomson" => "Thomson",
  301. "TOSHIBA" => "TOSHIBA",
  302. "ZaReason, Inc" => "ZaReason-Inc",
  303. );
  304. public static $compatibility = array(
  305. "A Platinum" => "A-platinum",
  306. "B Gold" => "B-gold",
  307. "C Silver" => "C-silver",
  308. "D Bronze" => "D-bronze",
  309. "E Garbage" => "E-garbage"
  310. );
  311. public static $subtypeSelect = 'notebook,netbook,tablet,not-specified';
  312. public static $architectureSelect = array(
  313. "not specified" => 'not-specified',
  314. "x86" => 'x86',
  315. "x86-64/amd64" => 'amd64',
  316. "MIPS" => 'MIPS',
  317. "ARM" => 'ARM',
  318. );
  319. public static $biosSelect = array(
  320. "not specified" => 'not-specified',
  321. "no" => 'no',
  322. "yes" => 'yes',
  323. "can be installed" => 'can-be-installed',
  324. );
  325. public static $preventWifiSelect = array(
  326. "not specified" => 'not-specified',
  327. "no" => 'no',
  328. "yes (please specify in the description entry)" => 'yes',
  329. );
  330. public static $installableSelect = array(
  331. "not specified" => 'not-specified',
  332. "no (please specify in the description entry)" => 'no',
  333. "yes" => 'yes',
  334. );
  335. // public static $installableSelect = 'not-specified,no,yes';
  336. public static $videoSelect = array(
  337. "not specified" => 'not-specified',
  338. "yes, with 3D acceleration" => "yes_with_3D",
  339. "yes, but without 3D acceleration" => "yes_without_3D",
  340. "it does not work" => "no",
  341. );
  342. public static $videoReverse = array(
  343. "yes_with_3D" => "works with 3D acceleration",
  344. "yes_without_3D" => "works, but without 3D acceleration",
  345. "no" => "it does not work",
  346. 'not-specified' => "not specified how it works",
  347. "" => ""
  348. );
  349. public static $wifiSelect = array(
  350. "not specified" => 'not-specified',
  351. 'yes' => 'yes',
  352. 'no' => 'no',
  353. 'there is no wifi card' => 'no-wifi-card',
  354. );
  355. public static $wifiReverse = array(
  356. "yes" => "it works",
  357. "no" => "it does not work",
  358. 'not-specified' => "not specified how it works",
  359. 'no-wifi-card' => 'there is no wifi card',
  360. "" => ""
  361. );
  362. public static $webcamSelect = array(
  363. 'not specified' => 'not-specified',
  364. 'it works' => 'yes',
  365. 'it does not work' => 'no',
  366. 'there is no webcam' => 'there-is-no-webcam',
  367. );
  368. public static $webcamReverse = array(
  369. "yes" => "it works",
  370. "no" => "it does not work",
  371. 'not-specified' => "not specified how it works",
  372. 'there-is-no-webcam' => 'there is no webcam',
  373. );
  374. public static function videoList()
  375. {
  376. return implode(',',array_values(self::$videoSelect));
  377. }
  378. public static function wifiList()
  379. {
  380. return implode(',',array_values(self::$wifiSelect));
  381. }
  382. public static function webcamList()
  383. {
  384. return implode(',',array_values(self::$webcamSelect));
  385. }
  386. public static function vendorsList()
  387. {
  388. return implode(',',array_values(self::$vendors));
  389. }
  390. public static function compatibilityList()
  391. {
  392. return implode(',',array_values(self::$compatibility));
  393. }
  394. public static function architectureList()
  395. {
  396. return implode(',',array_values(self::$architectureSelect));
  397. }
  398. public static function biosList()
  399. {
  400. return implode(',',array_values(self::$biosSelect));
  401. }
  402. public static function preventWifiList()
  403. {
  404. return implode(',',array_values(self::$preventWifiSelect));
  405. }
  406. public static function installableList()
  407. {
  408. return implode(',',array_values(self::$installableSelect));
  409. }
  410. }
  411. class ThreeGcards extends Wifi
  412. {
  413. public static $select = 'yes,no';
  414. }
  415. class Soundcards extends Hardware
  416. {
  417. public static $audioSelect = 'yes,no';
  418. public static $interface = "not-specified,PCI,ISA,USB,Firewire,Parallel,PCI-E,PCMCIA";
  419. }
  420. class Webcams extends Hardware
  421. {
  422. public static $select = 'yes,no';
  423. public static $interface = "not-specified,USB,Firewire,Parallel,Wifi,Serial";
  424. }
  425. class Bluetooth extends Hardware
  426. {
  427. public static $select = 'yes,no';
  428. public static $interface = "not-specified,USB,PCI,PCI-E,mini-PCI,mini-PCI-E,ExpressCard,PC-Card";
  429. }
  430. class Acquisitioncards extends Hardware
  431. {
  432. public static $select = 'yes,no';
  433. public static $interface = "not-specified,USB,PCI,PCI-E,mini-PCI,mini-PCI-E,ExpressCard,PC-Card,Firewire,Parallel,Serial";
  434. }
  435. class Fingerprintreaders extends Acquisitioncards
  436. {
  437. }
  438. class Ethernetcards extends Acquisitioncards
  439. {
  440. }
  441. class Sdcardreaders extends Acquisitioncards
  442. {
  443. }
  444. class Modems extends Acquisitioncards
  445. {
  446. }
  447. class Raidadapters extends Acquisitioncards
  448. {
  449. }
  450. class PCMCIAControllers extends Acquisitioncards
  451. {
  452. }
  453. class Hostcontrollers extends Acquisitioncards
  454. {
  455. public static $subtype = array(
  456. "PCMCIA Controller" => "pcmcia-controller",
  457. "USB Controller" => "usb-controller",
  458. "Firewire Controller" => "firewire-controller",
  459. "HECI Controller" => "heci-controller",
  460. );
  461. public static function subtypeList()
  462. {
  463. return implode(',',array_values(self::$subtype));
  464. }
  465. }