-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.php
59 lines (50 loc) · 1.39 KB
/
public.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
<?
include_once('config/config.php');
session_set_cookie_params(SE\SESS_LIFE, SE\SESS_PATH, SE\SESS_DOMAIN);
session_start();
include_once(SE\BASE_DIR. '/lib/class.httpRequest.php');
$http_request = new HTTPRequest('json');
/*
* Response object
*/
$response = array('status'=>0);
/*
* Set it for the class
*/
$http_request->setResponse($response);
/*
* Load the actual feature we want or default to something
*/
$http_request->loadFeature();
/*
* Get it from the class
*/
$response = $http_request->getResponse();
/*
* handle error (remove it if empty OR convert to string)
*/
if (isset($response['error'])) {
if (is_array($response['error'])) {
if (count($response['error']) == 0) {
unset($response['error']);
} else {
$response['error'] = implode("\n\n", $response['error']);
}
} else if (is_string($response['error'])) {
if (strlen(trim($response['error'])) == 0) {
unset($response['error']);
}
}
}
/*
* handle callbacks
*/
if (isset($_GET['callback']) || isset($_POST['callback'])) {
$callback = isset($_POST['callback'])?$_POST['callback']:$_GET['callback'];
// send the response with callback
echo '<script type="text/javascript">' .preg_replace('/[^\w\.]/', '', $callback). '(' .json_encode($response). '); </script>';
} else {
// send the response
echo json_encode($response);
}
?>