-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
193 lines (176 loc) · 6.51 KB
/
index.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/*
A very simple OAD database reader
The Open Anatomy Project
License: GNU General Public License
https://www.gnu.org/licenses/gpl-3.0.en.html
*/
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
// set classes for oad objects
class Structure_desc
{
var $type;
var $latin_name;
var $english_name;
var $location;
}
// set classes for database objects
class Structure_obj
{
var $name;
var $database;
var $latin_name;
var $position;
var $file;
var $file_size;
var $describer_file;
var $describer_file_size;
var $texture_file;
var $texture_file_size;
var $location;
var $polygon_count;
}
function compare_type($ind_a, $ind_b)
{
return strcmp($ind_a, $ind_b);
}
function compare_name($ind_a, $ind_b)
{
return strcmp($ind_a->latin_name, $ind_b->latin_name);
}
function print_files($file, $file_size)
{
if($file != "")
{
$file_type = explode(".",$file);
$output = '<br /><a href="'. $file . '">Download .' . $file_type[count($file_type)-1] . '</a>';
if($file_size != "") { $output .= ' (' . $file_size . ')'; }
return $output;
}
else { return ""; }
}
// set vars like it's c++ not php
$structure_object_count = 0;
$structure_object[] = 0;
$oad_structure_count = 0;
$oad_structure[] = 0;
$oad_type_count = 0;
$oad_type[] = 0;
// set feed URL
$databases_url = 'http://open-anatomy.org/databases.xml';
// Read the feed URL
$databases = simplexml_load_file($databases_url) or die('Error: Cannot connect to the databases.xml file.');
// Output Databases
$output_databases = '<u>Connected Databases:</u><br /><ul>';
foreach($databases->children() as $database)
{
$output_databases .= '<li><b><a href="' . $database->WEBSITE . '">' . $database->NAME . '</a></b><br />';
$output_databases .= 'Database URL: <a href="' . $database->DATABASE_URL . '">' . $database->DATABASE_URL . '</a>; OAD-File: <a href="' . $database->OAD_FILE . '">' . $database->OAD_FILE . '</a>; License: ' . $database->LICENSE . ';</li>';
// Catch databases results
if(simplexml_load_file($database->DATABASE_URL))
{
// load oad file
if(simplexml_load_file($database->OAD_FILE))
{
// get all structures
$oad = simplexml_load_file($database->OAD_FILE);
foreach ($oad->children() as $oad_object => $object)
{
// Simple check if this structure already exists in our database
$oad_exists = false;
$oad_type_exists = false;
foreach ($oad_structure as $structure)
{
if(isset($structure->latin_name))
{
// DIRRRRRRTY: json_encode the values to compare them
if(json_encode($object->LATIN_NAME) == json_encode($structure->latin_name)) { $oad_exists = true; }
if($oad_object == $structure->type) { $oad_type_exists = true; }
}
}
// only load types once into oad_type
if($oad_type_exists == false)
{
$oad_type[$oad_type_count] = $oad_object;
$oad_type_count = $oad_type_count + 1;
}
// OAD Structure doesn't exist yet? Put it in the database
if($oad_exists == false)
{
$oad_structure[$oad_structure_count] = new Structure_desc;
$oad_structure[$oad_structure_count] -> type = $oad_object;
$oad_structure[$oad_structure_count] -> latin_name = $object->LATIN_NAME;
$oad_structure[$oad_structure_count] -> english_name = $object->ENGLISH_NAME;
$oad_structure[$oad_structure_count] -> location = $object->LOCATION;
$oad_structure_count = $oad_structure_count + 1;
}
}
}
else
{
print '<b>ERROR</b> OAD File: ' . $database->OAD_FILE . ' required by ' . $database->WEBSITE . ' can not be reached<br />';
}
// Put structure in the database
$database_curr = simplexml_load_file($database->DATABASE_URL);
foreach ($database_curr->children() as $database_object => $object)
{
if($database_object == "STRUCTURE")
{
$structure_object[$structure_object_count] = new Structure_obj;
$structure_object[$structure_object_count] -> name = $object->NAME;
$structure_object[$structure_object_count] -> database = $database->NAME;
$structure_object[$structure_object_count] -> latin_name = $object->LATIN_NAME;
$structure_object[$structure_object_count] -> position = $object->POSITION;
$structure_object[$structure_object_count] -> file = $object->FILE;
$structure_object[$structure_object_count] -> file_size = $object->FILE_SIZE;
$structure_object[$structure_object_count] -> describer_file = $object->DESCRIBER_FILE;
$structure_object[$structure_object_count] -> describer_file_size = $object->DESCRIBER_FILE_SIZE;
$structure_object[$structure_object_count] -> texture_file = $object->TEXTURE_FILE;
$structure_object[$structure_object_count] -> texture_file_size = $object->TEXTURE_FILE_SIZE;
$structure_object[$structure_object_count] -> polygon_count = $object->POLYGON_COUNT;
$structure_object_count++;
}
}
}
else
{
print '<b>ERROR</b> Database: ' . $database->DATABASE_URL . ' required by ' . $database->WEBSITE . ' can not be reached<br />';
}
}
$output_databases .= '</ul>';
// Sort oad structues by name
usort($oad_type, "compare_type");
// Sort oad structues by name
usort($oad_structure, "compare_name");
print '<!DOCTYPE html><head><meta charset="utf-8"/><title>Open Anatomy Database overview</title></head><body>';
foreach($oad_type as $type)
{
print '<b><u>' . $type . ':</b></u><br>';
// Now generate some output
foreach ($oad_structure as $structure)
{
if($type == $structure->type)
{
print '<b>' . $structure->latin_name . ' (' . $structure->english_name . '):</b><ul>';
$output_object = "";
foreach($structure_object as $object)
{
// Get every object of the same name as the structure | DIRRRRRRTY: json_encode the values to compare them
if(json_encode($object->latin_name) == json_encode($structure->latin_name))
{
$output_object .= '<li><u>' . $object->database . '</u>: ' . $object->name;
if($object->polygon_count != '') { $output_object .= ' (Polygons: ' . $object->polygon_count . ')'; }
$output_object .= print_files($object->file, $object->file_size);
$output_object .= print_files($object->describer_file, $object->describer_file_size);
$output_object .= print_files($object->texture_file, $object->texture_file_size);
$output_object .= '</li>';
}
}
print $output_object;
print '</ul>';
}
}
}
print $output_databases . '</body>';
?>