corrade-http-templates – Diff between revs 8 and 75

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 8 Rev 75
1 <?php 1 <?php
2   2  
3 ########################################################################### 3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## 4 ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ##
5 ########################################################################### 5 ###########################################################################
6 ## This is a script that uses Corrade's "getregiondata" command in order ## 6 ## This is a script that uses Corrade's "getregiondata" command in order ##
7 ## to retrieve statistics on the current simulator. ## 7 ## to retrieve statistics on the current simulator. ##
8 ########################################################################### 8 ###########################################################################
9   9  
10 ########################################################################### 10 ###########################################################################
11 ## CONFIGURATION ## 11 ## CONFIGURATION ##
12 ########################################################################### 12 ###########################################################################
13   13  
14 require_once('config.php'); 14 require_once('config.php');
15 require_once('functions.php'); 15 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
-   16 require_once('vendor/was/utilities/src/collections/arrays/arrays.php');
16   17  
17 ########################################################################### 18 ###########################################################################
18 ## INTERNALS ## 19 ## INTERNALS ##
19 ########################################################################### 20 ###########################################################################
20   21  
21 if(!isset($_POST["query"])) return; 22 if(!isset($_POST["query"])) return;
22   23  
23 #### 24 ####
24 # I. Get the query from the javascript. 25 # I. Get the query from the javascript.
25 $query = $_POST["query"]; 26 $query = $_POST["query"];
26   27  
27 # This constructs the command as an array of key-value pairs. 28 # This constructs the command as an array of key-value pairs.
28 $params = array( 29 $params = array(
29 'command' => 'getregiondata', 30 'command' => 'getregiondata',
30 'group' => $GROUP, 31 'group' => $GROUP,
31 'data' => $query, 32 'data' => $query,
32 'password' => $PASSWORD 33 'password' => $PASSWORD
33 ); 34 );
34   35  
35 # We now escape each key and value: this is very important, because the 36 # We now escape each key and value: this is very important, because the
36 # data we send to Corrade may contain the '&' or '=' characters (we don't 37 # data we send to Corrade may contain the '&' or '=' characters (we don't
37 # in this example though but this will not hurt anyone). 38 # in this example though but this will not hurt anyone).
38 array_walk($params, 39 array_walk($params,
39 function(&$value, $key) { 40 function(&$value, $key) {
40 $value = rawurlencode($key)."=".rawurlencode($value); 41 $value = rawurlencode($key)."=".rawurlencode($value);
41 } 42 }
42 ); 43 );
43 $postvars = implode('&', $params); 44 $postvars = implode('&', $params);
44   45  
45 #### 46 ####
46 # II. Set the options, send the request and then display the outcome. 47 # II. Set the options, send the request and then display the outcome.
47 if (!($curl = curl_init())) return; 48 if (!($curl = curl_init())) return;
48   49  
49 curl_setopt($curl, CURLOPT_URL, $URL); 50 curl_setopt($curl, CURLOPT_URL, $URL);
50 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 51 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
51 curl_setopt($curl, CURLOPT_POST, true); 52 curl_setopt($curl, CURLOPT_POST, true);
52 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 53 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
53 curl_setopt($curl, CURLOPT_ENCODING, true); 54 curl_setopt($curl, CURLOPT_ENCODING, true);
54 $result = str_getcsv( 55 $result = str_getcsv(
55 urldecode( 56 urldecode(
56 wasKeyValueGet( 57 wasKeyValueGet(
57 "data", 58 "data",
58 curl_exec($curl) 59 curl_exec($curl)
59 ) 60 )
60 ) 61 )
61 ); 62 );
62 curl_close($curl); 63 curl_close($curl);
63   64  
64 #### 65 ####
65 # III. Dump JSON for AJAX. 66 # III. Dump JSON for AJAX.
66 echo json_encode( 67 echo json_encode(
67 array_combine( 68 array_combine(
68 wasArrayStride( 69 wasArrayStride(
69 $result, 70 $result,
70 2 71 2
71 ), 72 ),
72 wasArrayStride( 73 wasArrayStride(
73 array_slice( 74 array_slice(
74 $result, 75 $result,
75 1 76 1
76 ), 77 ),
77 2 78 2
78 ) 79 )
79 ) 80 )
80 ); 81 );
81   82  
82 ?> 83 ?>
83   84  
84   85