-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetsky.php
71 lines (64 loc) · 1.42 KB
/
getsky.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
function typify($str)
{
$vval = strtolower($str);
if ( ($fval = filter_var($vval, FILTER_VALIDATE_INT,
array('flags' => FILTER_FLAG_ALLOW_OCTAL|FILTER_FLAG_ALLOW_HEX))) !== false )
{
return $fval;
}
if ( ($fval = filter_var($vval, FILTER_VALIDATE_FLOAT)) !== false )
{
return $fval;
}
if ( ($fval = filter_var($vval, FILTER_VALIDATE_BOOLEAN,
array('flags' => FILTER_NULL_ON_FAILURE))) !== null )
{
return $fval;
}
return $str;
}
function skyboxXMLToArray($node)
{
if (!$node->hasAttributes() && $node->childNodes->length == 1
&& $node->childNodes->item(0)->nodeType == XML_TEXT_NODE)
{
return typify($node->textContent);
}
$res = array();
foreach ($node->attributes as $name => $val)
{
$res[$name] = typify(strtolower($val->value));
}
foreach ($node->childNodes as $child)
{
if ($child->nodeType == XML_ELEMENT_NODE)
{
$child_data = skyboxXMLToArray($child);
if ($child->tagName == 'map')
{
$name = $child_data['name'];
unset($child_data['name']);
$res[$name] = $child_data;
}
else
{
$res[$child->tagName] = $child_data;
}
}
}
return $res;
}
header('Content-Type: application/json');
try
{
$doc = new DomDocument();
$doc->load('elc/skybox/skybox_defs.xml', LIBXML_NOENT);
$res = skyboxXMLToArray($doc->documentElement);
$json_data = json_encode($res);
echo $json_data;
}
catch (Exception $e)
{
echo json_encode(array('error' => $e->getMessage()));
}