This repository has been archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.php
63 lines (55 loc) · 1.54 KB
/
api.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
<?php
require_once 'core/init.php';
if (isset($_GET['method'])) {
header('Content-Type: application/json; charset=utf-8');
if ($_GET['method'] === 'object') {
$uri = $KSamsok->uriFormat($_GET['uri'], 'rawurl');
// if the URI is valid
if ($uri !== false) {
$result = $db::getObject($uri);
if (!$result) {
apiError('An object with this URI does not exists in the database.');
} else {
echo json_encode($result, JSON_UNESCAPED_SLASHES);
die();
}
} else {
apiError('Invalid URI or no URI parameter set.');
}
} elseif ($_GET['method'] === 'box') {
$box[] = $_GET['south'];
$box[] = $_GET['east'];
$box[] = $_GET['north'];
$box[] = $_GET['west'];
foreach ($box as $coord) {
if (!is_numeric($coord)) {
apiError('Invalid parameters or parameter values.');
die();
}
}
$result = $db::boxSearch($box);
if (!$result) {
apiError('No objects exist within this bounding box.');
} else {
echo json_encode($result, JSON_UNESCAPED_SLASHES);
die();
}
} elseif ($_GET['method'] === 'user') {
//
$result = db::getObjectsByUsername($_GET['user']);
if (!$result) {
apiError('Missing user parameter or invalid user/user has no images.');
} else {
echo json_encode($result, JSON_UNESCAPED_SLASHES);
die();
}
} else {
apiError('Invalid API method.');
}
} else {
apiError('No method specified.');
}
function apiError($message) {
echo '{ "error:": "' . $message . '"}';
die();
}