]> matita.cs.unibo.it Git - logicplayer.git/blob - public_html/util.php
new initial commit
[logicplayer.git] / public_html / util.php
1 <?php
2 function __json_encode($data) {
3         if (is_array ( $data ) || is_object ( $data )) {
4                 $islist = is_array ( $data ) && (empty ( $data ) || array_keys ( $data ) === range ( 0, count ( $data ) - 1 ));
5
6                 if ($islist) {
7                         $json = '[' . implode ( ',', array_map ( '__json_encode', $data ) ) . ']';
8                 } else {
9                         $items = Array ();
10                         foreach ( $data as $key => $value ) {
11                                 $items [] = __json_encode ( "$key" ) . ':' . __json_encode ( $value );
12                         }
13                         $json = '{' . implode ( ',', $items ) . '}';
14                 }
15         } elseif (is_string ( $data )) {
16                 $json = '"' . addcslashes ( $data, '\\"' ) . '"';
17         } else {
18                 // int, floats, bools, null
19                 $json = strtolower ( var_export ( $data, true ) );
20         }
21         return $json;
22 }
23
24 function GET_check()
25 {
26 if (!isset($_GET['scope']) or !isset($_GET['type']) or !($_GET['lat']) or !isset($_GET['lng']) or !isset($_GET['radius']) or !isset($_GET['timemin']) or !isset($_GET['timemax']) or !isset($_GET['status']))
27         return false;
28 else return true;
29 }
30 function POST_check($params)
31 {
32 if (!$params->type or !$params->lat or !$params->lng) return false;
33 else return true;
34 }
35
36 function NOTIFY_check($params)
37 {
38 if (!$params->event_id or !$params->lat or !$params->lng or !$params->status) return false;
39 else return true;
40 }
41 ?>