corrade-http-templates – Diff between revs 2 and 12

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 2 Rev 12
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 that uses Corrade's "getterrainheight" command in ## 6 ## This is a script that uses Corrade's "getterrainheight" command in ##
7 ## order to retrieve the maximal terrain height of a region. ## 7 ## order to retrieve the maximal terrain height of a region. ##
8 ########################################################################### 8 ###########################################################################
9   9  
10 ########################################################################### 10 ###########################################################################
11 ## CONFIGURATION ## 11 ## CONFIGURATION ##
12 ########################################################################### 12 ###########################################################################
13   13  
14 // The configuration file for this script containing the settings. 14 # The configuration file for this script containing the settings.
15 include_once("config.php"); -  
16 -  
17 ########################################################################### -  
18 ## INTERNALS ## 15 require_once('config.php');
19 ########################################################################### 16 require_once('functions.php');
20   17  
21 ########################################################################### 18 ###########################################################################
22 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
23 ########################################################################### -  
24 function wasKeyValueGet($key, $data) { -  
25 return array_reduce( -  
26 explode( -  
27 "&", -  
28 $data -  
29 ), -  
30 function($o, $p) { -  
31 $x = explode("=", $p); -  
32 return array_shift($x) != $o ? $o : array_shift($x); -  
33 }, -  
34 $key -  
35 ); 19 ## INTERNALS ##
36 } 20 ###########################################################################
37 21
38 #### 22 ####
39 # I. Get the terrain height. 23 # I. Get the terrain height.
40 $params = array( 24 $params = array(
41 'command' => 'getterrainheight', 25 'command' => 'getterrainheight',
42 'group' => $GROUP, 26 'group' => $GROUP,
43 'entity' => 'region', 27 'entity' => 'region',
44 'password' => $PASSWORD 28 'password' => $PASSWORD
45 ); 29 );
46 30
47 # We now escape each key and value: this is very important, because the 31 # We now escape each key and value: this is very important, because the
48 # data we send to Corrade may contain the '&' or '=' characters (we don't 32 # data we send to Corrade may contain the '&' or '=' characters (we don't
49 # in this example though but this will not hurt anyone). 33 # in this example though but this will not hurt anyone).
50 array_walk($params, 34 array_walk($params,
51 function(&$value, $key) { 35 function(&$value, $key) {
52 $value = urlencode($key)."=".urlencode($value); 36 $value = urlencode($key)."=".urlencode($value);
53 } 37 }
54 ); 38 );
55 $postvars = implode('&', $params); 39 $postvars = implode('&', $params);
56 40
57 # Set the options, send the request and then display the outcome 41 # Set the options, send the request and then display the outcome
58 if (!($curl = curl_init())) { 42 if (!($curl = curl_init())) {
59 echo "Could not initialise CURL".PHP_EOL; 43 echo "Could not initialise CURL".PHP_EOL;
60 } 44 }
61 45
62 curl_setopt($curl, CURLOPT_URL, $URL); 46 curl_setopt($curl, CURLOPT_URL, $URL);
63 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
64 curl_setopt($curl, CURLOPT_POST, true); 48 curl_setopt($curl, CURLOPT_POST, true);
65 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
66 $return = curl_exec($curl); 50 $return = curl_exec($curl);
67 curl_close($curl); 51 curl_close($curl);
68   52  
69 $success = urldecode( 53 $success = urldecode(
70 wasKeyValueGet( 54 wasKeyValueGet(
71 "success", 55 "success",
72 $return 56 $return
73 ) 57 )
74 ); 58 );
75   59  
76 // Unable to get the region heights? 60 // Unable to get the region heights?
77 if($success == 'False') return -1; 61 if($success == 'False') return -1;
78   62  
79 #### 63 ####
80 # II. Get the array of terrain heights and output the maximum value. 64 # II. Get the array of terrain heights and output the maximum value.
81 echo max( 65 echo max(
82 str_getcsv( 66 str_getcsv(
83 urldecode( 67 urldecode(
84 wasKeyValueGet( 68 wasKeyValueGet(
85 "data", 69 "data",
86 $return 70 $return
87 ) 71 )
88 ) 72 )
89 ) 73 )
90 ); 74 );
91   75  
92 return 0; 76 return 0;
93   77  
94 ?> 78 ?>
95   79  
96
Generated by GNU Enscript 1.6.5.90.
80
Generated by GNU Enscript 1.6.5.90.
97   81  
98   82  
99   83