-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_utils.php
65 lines (53 loc) · 1.01 KB
/
api_utils.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
<?php
require_once(dirname(__FILE__) . '/lib.php');
//--------------------------------------------------------------------------------------------------
function api_output($obj, $callback)
{
$status = 404;
// $obj may be array (e.g., for citeproc)
if (is_array($obj))
{
if (isset($obj['status']))
{
$status = $obj['status'];
}
}
// $obj may be object
if (is_object($obj))
{
if (isset($obj->status))
{
$status = $obj->status;
}
}
switch ($status)
{
case 303:
header('HTTP/1.1 404 See Other');
break;
case 404:
header('HTTP/1.1 404 Not Found');
break;
case 410:
header('HTTP/1.1 410 Gone');
break;
case 500:
header('HTTP/1.1 500 Internal Server Error');
break;
default:
break;
}
header("Content-type: text/plain");
header("Cache-control: max-age=3600");
if ($callback != '')
{
echo $callback . '(';
}
//echo json_encode($obj, JSON_PRETTY_PRINT);
echo json_format(json_encode($obj));
if ($callback != '')
{
echo ')';
}
}
?>