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

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 12 Rev 77
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 require_once('config.php'); 15 require_once('config.php');
16 require_once('functions.php'); 16 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
17   17  
18 ########################################################################### 18 ###########################################################################
19 ## INTERNALS ## 19 ## INTERNALS ##
20 ########################################################################### 20 ###########################################################################
21 21
22 #### 22 ####
23 # I. Get the terrain height. 23 # I. Get the terrain height.
24 $params = array( 24 $params = array(
25 'command' => 'getterrainheight', 25 'command' => 'getterrainheight',
26 'group' => $GROUP, 26 'group' => $GROUP,
27 'entity' => 'region', 27 'entity' => 'region',
28 'password' => $PASSWORD 28 'password' => $PASSWORD
29 ); 29 );
30 30
31 # 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
32 # 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
33 # in this example though but this will not hurt anyone). 33 # in this example though but this will not hurt anyone).
34 array_walk($params, 34 array_walk($params,
35 function(&$value, $key) { 35 function(&$value, $key) {
36 $value = urlencode($key)."=".urlencode($value); 36 $value = urlencode($key)."=".urlencode($value);
37 } 37 }
38 ); 38 );
39 $postvars = implode('&', $params); 39 $postvars = implode('&', $params);
40 40
41 # Set the options, send the request and then display the outcome 41 # Set the options, send the request and then display the outcome
42 if (!($curl = curl_init())) { 42 if (!($curl = curl_init())) {
43 echo "Could not initialise CURL".PHP_EOL; 43 echo "Could not initialise CURL".PHP_EOL;
44 } 44 }
45 45
46 curl_setopt($curl, CURLOPT_URL, $URL); 46 curl_setopt($curl, CURLOPT_URL, $URL);
47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
48 curl_setopt($curl, CURLOPT_POST, true); 48 curl_setopt($curl, CURLOPT_POST, true);
49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
50 $return = curl_exec($curl); 50 $return = curl_exec($curl);
51 curl_close($curl); 51 curl_close($curl);
52   52  
53 $success = urldecode( 53 $success = urldecode(
54 wasKeyValueGet( 54 wasKeyValueGet(
55 "success", 55 "success",
56 $return 56 $return
57 ) 57 )
58 ); 58 );
59   59  
60 // Unable to get the region heights? 60 // Unable to get the region heights?
61 if($success == 'False') return -1; 61 if($success == 'False') return -1;
62   62  
63 #### 63 ####
64 # 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.
65 echo max( 65 echo max(
66 str_getcsv( 66 str_getcsv(
67 urldecode( 67 urldecode(
68 wasKeyValueGet( 68 wasKeyValueGet(
69 "data", 69 "data",
70 $return 70 $return
71 ) 71 )
72 ) 72 )
73 ) 73 )
74 ); 74 );
75   75  
76 return 0; 76 return 0;
77   77  
78 ?> 78 ?>
79   79  
80
Generated by GNU Enscript 1.6.5.90.
80
Generated by GNU Enscript 1.6.5.90.
81   81  
82   82  
83   83