-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathnasainfo.php
43 lines (35 loc) · 1.62 KB
/
nasainfo.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
<?php
$catalogURLTemplate = 'http://nssdc.gsfc.nasa.gov/nmc/masterCatalog.do?sc=%s';
$designator = htmlspecialchars($_GET['intldes']);
$redirect = filter_var($_GET['redirect'], FILTER_VALIDATE_BOOLEAN);
if ($designator) {
if ($redirect) {
header('Location: ' . sprintf($catalogURLTemplate, $designator), true, 302);
exit;
} else {
$catalogEntryHtml = file_get_contents(sprintf($catalogURLTemplate, $designator));
if ($catalogEntryHtml) {
$catalogEntryDocument = new DOMDocument();
if ($catalogEntryDocument->loadHTML($catalogEntryHtml)) {
$xpath = new DOMXPath($catalogEntryDocument);
$match = $xpath->query('//div[@id="contentwrapper"]//div[@class="urone"]');
if ($match->length > 0) {
$description = '';
$descriptionParts = $match[0]->childNodes;
for ($i = 1; $i < $descriptionParts->length; ++$i) {
$description .= trim($descriptionParts[$i]->nodeValue);
}
header('Content-Type: text/json', true, 200);
$data = array(
'description' => $description
);
echo json_encode($data);
exit;
}
}
}
}
}
// fall back - if any error happened during data extraction above, return 404
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
?>