-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcave_symbol_functions.php
161 lines (151 loc) · 4.45 KB
/
cave_symbol_functions.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
//write HTML header
function writeHeader($title,$subtitle,$script) {
header("Content-type: text/html");
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
print "<!DOCTYPE html PUBLIC \"-//AndiNeumann//DTD XHTML-with extended modules//EN\" \"../../resources/xhtml-extended.dtd\">\n";
print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
print "<head>\n";
print "<title>$title</title>\n";
print "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n";
print "<meta name=\"author\" content=\"Andreas Neumann\" />\n";
print "<meta name=\"keywords\" content=\"UIS, cave symbols, list\" />\n";
if ($script) {
print "$script\n";
}
print "</head>\n";
print "<body bgcolor=\"lightgrey\">\n";
print "<h1>$title</h1>\n";
print "<h2>$subtitle</h2>\n";
}
//extract content of a GUI-element according to language
function getGuiValue($doc,$id,$language) {
$parentNode = $doc->getElementById($id);
$nodeList = $parentNode->getElementsByTagName($language);
$content = $nodeList->item(0)->nodeValue;
return $content;
}
//extract content of a text element without escaping tags
function dumpText($doc,$id,$language) {
$parentNode = $doc->getElementById($id);
$nodeList = $parentNode->getElementsByTagName($language);
$content = $doc->saveXML($nodeList->item(0));
return $content;
}
//extract symbolName, input is dom node of name "cave_symbol"
function getSymbolName($node,$language) {
$child = $node->firstChild;
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == "translationsSymbolName") {
$content = getChildContent($child,$language);
break;
}
}
$child = $child->nextSibling;
}
return $content;
}
//extract symbolNames for all languages, input is dom node of name "cave_symbol"
function getSymbolTranslations($node) {
$child = $node->firstChild;
$content = array();
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == "translationsSymbolName") {
$grandchild = $child->firstChild;
while ($grandchild) {
if ($grandchild->nodeType == 1) {
$language = $grandchild->nodeName;
$content[$language] = $grandchild->nodeValue;
}
$grandchild = $grandchild->nextSibling;
}
}
}
$child = $child->nextSibling;
}
return $content;
}
//extract translationsData, input is dom node of name "cave_symbol"
function getExplanations($node,$language) {
$child = $node->firstChild;
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == "translationsExplanations") {
$content = getChildContent($child,$language);
$content = str_replace("\\n","<br />",$content);
break;
}
}
$child = $child->nextSibling;
}
return $content;
}
//return content of a child of a node with a specific node_name
function getChildContent($node,$node_name) {
$child = $node->firstChild;
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == $node_name) {
$content = $child->nodeValue;
break;
}
}
$child = $child->nextSibling;
}
return $content;
}
//check if a dom node has photo child nodes
function checkHasPhotos($node) {
$child = $node->firstChild;
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == "photos") {
if ($child->hasChildNodes()) {
return true;
}
else {
return false;
}
break;
}
}
$child = $child->nextSibling;
}
}
//check if a dom node has photo child nodes
function returnPhotoData($node,$language) {
$child = $node->firstChild;
$photoDat = array();
while ($child) {
if ($child->nodeType == 1) {
if ($child->nodeName == "photos") {
$photoElement = $child->firstChild;
while ($photoElement) {
if ($photoElement->nodeType == 1) {
$photoData = array();
$photoData["filename"] = $photoElement->getAttribute("filename");
$photoData["title"] = getChildContent($photoElement,$language);
$photoData["width"] = $photoElement->getAttribute("width");
$photoData["height"] = $photoElement->getAttribute("height");
$photoData["photographer"] = $photoElement->getAttribute("photographer");
$photoData["caveRegionName"] = $photoElement->getAttribute("caveRegionName");
$photoData["year"] = $photoElement->getAttribute("year");
array_push($photoDat,$photoData);
}
$photoElement = $photoElement->nextSibling;
}
break;
}
}
$child = $child->nextSibling;
}
return $photoDat;
}
//write closing of HTML file
function writeHTMLEnd() {
print "</body>\n";
print "</html>\n";
}
?>