3 require_once('../include/db.php');
5 header('Content-type: application/json');
6 $maxage = config('jsonCacheMaxAge');
7 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT');
8 header("Cache-Control: maxage=$maxage");
10 function exit_with_error($status, $details = array()) {
11 $details['status'] = $status;
12 echo json_encode($details);
16 function exit_with_success($details = array()) {
17 $details['status'] = 'OK';
18 echo json_encode($details);
25 exit_with_error('DatabaseConnectionError');
29 function camel_case_words_separated_by_underscore($name) {
30 return implode('', array_map('ucfirst', explode('_', $name)));
33 function require_format($key, $value, $pattern) {
34 if (!preg_match($pattern, $value))
35 exit_with_error('Invalid' . camel_case_words_separated_by_underscore($key), array('value' => $value));
38 function require_existence_of($array, $list_of_arguments, $prefix = '') {
41 foreach ($list_of_arguments as $key => $pattern) {
42 $name = camel_case_words_separated_by_underscore($prefix . $key);
43 if (!array_key_exists($key, $array))
44 exit_with_error($name . 'NotSpecified');
45 require_format($name, $array[$key], $pattern);