-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjson.php
118 lines (110 loc) · 2.91 KB
/
json.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
<?php
/**
* EGroupware digital ROCK Rankings webservice access: json
*
* Usage: http://www.digitalrock.de/egroupware/json.php?comp=yyy&cat=zzz[&route=xxx][&debug=1]
*
* @param comp competition number
* @param cat category number or rkey
* @param route -1 = general result (default)
* 0 = qualification
* 1 = 2. qualification (if applicable)
* 2 = further heats
* @param debug 1: content-type: text/html
* 2: additionally original route array
*
* @package ranking
* @link http://www.egroupware.org
* @link http://www.digitalROCK.de
* @author Ralf Becker <RalfBecker@digitalrock.de>
* @copyright 2010 by Ralf Becker <RalfBecker@digitalrock.de>
* @version $Id$
*/
use EGroupware\Api;
use EGroupware\Ranking\Export;
$GLOBALS['egw_info'] = array(
'flags' => array(
'currentapp' => 'ranking',
'nonavbar' => True,
'noheader' => True,
'autocreate_session_callback' => 'check_anon_access',
'nocachecontrol'=> 'public',
));
include('../header.inc.php');
/**
* Create anonymous session without checking credentials
*
* @param array &$anon_account anon account_info with keys 'login', 'passwd' and optional 'passwd_type'
* @return boolean|string string with sessionid or false on error (no anonymous user)
*/
function check_anon_access(&$anon_account)
{
$anon_account = null;
// create session without checking auth: create(..., false, false)
return $GLOBALS['egw']->session->create('anonymous@'.$GLOBALS['egw_info']['user']['domain'],
'', 'text', false, false);
}
$result = Export::export();
$encoding = Api\Translation::charset();
if (!isset($_GET['debug']) || !$_GET['debug'])
{
if ($_GET['callback']) // JSONP uses application/javascript as content-type
{
header('Content-Type: application/javascript; charset='.$encoding);
}
else
{
header('Content-Type: application/json; charset='.$encoding);
}
Api\Session::cache_control(isset($result['expires']) ? $result['expires'] : Export::EXPORT_DEFAULT_EXPIRES);
header('Access-Control-Allow-Origin: *');
if (isset($result['etag']))
{
if ($result['etag'][0] != '"') $result['etag'] = '"'.$result['etag'].'"';
header('Etag: '.$result['etag']);
}
if (isset($_SERVER['HTTP_IF_MATCH']) && $_SERVER['HTTP_IF_MATCH'] === $result['etag'])
{
header('HTTP/1.1 304 Not Modified');
exit();
}
}
else
{
header('Content-Type: application/json; charset='.$encoding);
}
/**
* Remove all empty (null or "") values from an array
*
* @param array $arr
* @return array
*/
function remove_empty(array $arr)
{
foreach($arr as $key => &$val)
{
if (is_array($val))
{
$val = remove_empty($val);
}
elseif ((string)$val === '')
{
unset($arr[$key]);
}
}
return $arr;
}
$json = json_encode($result=remove_empty($result));
if (isset($_GET['debug']) && $_GET['debug'])
{
echo json_encode($result, JSON_PRETTY_PRINT);
}
// jsonp callback
elseif ($_GET['callback'])
{
echo $_GET['callback'].'('.$json.");\n";
}
else
{
echo $json;
}