corrade-http-templates – Diff between revs 76 and 82

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 76 Rev 82
1 <?php 1 <?php
2   2  
3 ########################################################################### 3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## 4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
5 ########################################################################### 5 ###########################################################################
6 ## This is a script uses Corrade to fetch the top scripts on a region ## 6 ## This is a script uses Corrade to fetch the top scripts on a region ##
7 ## and then passes that data back as a JSON object to be used with the ## 7 ## and then passes that data back as a JSON object to be used with the ##
8 ## DataTables JQuery extension. ## 8 ## DataTables JQuery extension. ##
9 ########################################################################### 9 ###########################################################################
10   10  
11 ########################################################################### 11 ###########################################################################
12 ## CONFIGURATION ## 12 ## CONFIGURATION ##
13 ########################################################################### 13 ###########################################################################
14   14  
15 require_once('config.php'); 15 require_once('config.php');
16 require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); 16 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
17 require_once('vendor/was/utilities/src/formats/csv/csv.php'); 17 require_once('vendor/was/utilities/src/formats/csv/csv.php');
18   18  
19 ########################################################################### 19 ###########################################################################
20 ## INTERNALS ## 20 ## INTERNALS ##
21 ########################################################################### 21 ###########################################################################
22   22  
23 #### 23 ####
24 # I. Get the top scripts. 24 # I. Get the top scripts.
25 $params = array( 25 $params = array(
26 'command' => 'getregiontop', 26 'command' => 'getregiontop',
27 'group' => $GROUP, 27 'group' => $GROUP,
28 'password' => $PASSWORD, 28 'password' => $PASSWORD,
29 'type' => 'scripts' 29 'type' => 'scripts'
30 ); 30 );
31 array_walk($params, 31 array_walk($params,
32 function(&$value, $key) { 32 function(&$value, $key) {
33 $value = rawurlencode($key)."=".rawurlencode($value); 33 $value = urlencode($key)."=".urlencode($value);
34 } 34 }
35 ); 35 );
36 $postvars = implode('&', $params); 36 $postvars = implode('&', $params);
37 if (!($curl = curl_init())) { 37 if (!($curl = curl_init())) {
38 print 0; 38 print 0;
39 return; 39 return;
40 } 40 }
41 curl_setopt($curl, CURLOPT_URL, $URL); 41 curl_setopt($curl, CURLOPT_URL, $URL);
42 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 42 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
43 curl_setopt($curl, CURLOPT_POST, true); 43 curl_setopt($curl, CURLOPT_POST, true);
44 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 44 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
45 curl_setopt($curl, CURLOPT_ENCODING, true); 45 curl_setopt($curl, CURLOPT_ENCODING, true);
46 $return = curl_exec($curl); 46 $return = curl_exec($curl);
47 curl_close($curl); 47 curl_close($curl);
48   48  
49 #### 49 ####
50 # II. Check for success. 50 # II. Check for success.
51 $success = urldecode( 51 $success = urldecode(
52 wasKeyValueGet( 52 wasKeyValueGet(
53 "success", 53 "success",
54 $return 54 $return
55 ) 55 )
56 ); 56 );
57 if($success == 'False') { 57 if($success == 'False') {
58 echo 'Unable to query the top scripts: ' 58 echo 'Unable to query the top scripts: '
59 .urldecode( 59 .urldecode(
60 wasKeyValueGet( 60 wasKeyValueGet(
61 "error", 61 "error",
62 $return 62 $return
63 ) 63 )
64 ); 64 );
65 die; 65 die;
66 } 66 }
67   67  
68 #### 68 ####
69 # III. Dump JSON for DataTables. 69 # III. Dump JSON for DataTables.
70 echo json_encode( 70 echo json_encode(
71 array( 71 array(
72 "data" => 72 "data" =>
73 array_chunk( 73 array_chunk(
74 wasCSVToArray( 74 wasCSVToArray(
75 urldecode( 75 urldecode(
76 wasKeyValueGet( 76 wasKeyValueGet(
77 "data", 77 "data",
78 $return 78 $return
79 ) 79 )
80 ) 80 )
81 ), 81 ),
82 5 # We split the CSV in 5: score, task name, UUID, Owner and Position 82 5 # We split the CSV in 5: score, task name, UUID, Owner and Position
83 ) 83 )
84 ) 84 )
85 ); 85 );
86   86  
87 ?> 87 ?>
88   88  
89   89  
90   90