Add mobiledetectlib (#1806)
[openemr.git] / vendor / mobiledetect / mobiledetectlib / export / exportToJSON.php
blobe2c72aece1c565a0d40b2bb5d6afefc8764f6ad8
1 <?php
2 /**
3 * Mobile Detect Library
4 * - export -
5 * =====================
7 * Use the resulting JSON export file in other languages
8 * other than PHP. Always check for 'version' key because
9 * new major versions can modify the structure of the JSON file.
11 * The result of running this script is the export.json file.
13 * @license Code and contributions have 'MIT License'
14 * More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
18 // Included nicejson function to beautify the result JSON file.
19 // This library is not mandatory.
20 if( file_exists(dirname(__FILE__).'/nicejson/nicejson.php') ) {
21 include_once dirname(__FILE__).'/nicejson/nicejson.php';
24 // Include Mobile Detect.
25 require_once dirname(__FILE__).'/../Mobile_Detect.php';
26 $detect = new Mobile_Detect;
28 $json = array(
29 // The current version of Mobile Detect class that
30 // is being exported.
31 'version' => $detect->getScriptVersion(),
33 // All headers that trigger 'isMobile' to be 'true',
34 // before reaching the User-Agent match detection.
35 'headerMatch' => $detect->getMobileHeaders(),
37 // All possible User-Agent headers.
38 'uaHttpHeaders' => $detect->getUaHttpHeaders(),
40 // All the regexes that trigger 'isMobile' or 'isTablet'
41 // to be true.
42 'uaMatch' => array(
43 // If match is found, triggers 'isMobile' to be true.
44 'phones' => $detect->getPhoneDevices(),
45 // Triggers 'isTablet' to be true.
46 'tablets' => $detect->getTabletDevices(),
47 // If match is found, triggers 'isMobile' to be true.
48 'browsers' => $detect->getBrowsers(),
49 // If match is found, triggers 'isMobile' to be true.
50 'os' => $detect->getOperatingSystems(),
51 // Various utilities. To be further discussed.
52 'utilities' => $detect->getUtilities()
56 $fileName = dirname(__FILE__).'/../Mobile_Detect.json';
57 // Write the JSON file to disk.11
58 // You can import this file in your app.
59 if (file_put_contents(
60 $fileName,
61 function_exists('json_format') ? json_format($json) : json_encode($json)
62 )) {
63 echo 'Done. Check '.realpath($fileName).' file.';
65 else {
66 echo 'Failed to write '.realpath($fileName).' to disk.';