corrade-http-templates – Diff between revs 11 and 70

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 11 Rev 70
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 can be used to download a texture using Corrade ## 6 ## This is a script that can be used to download a texture using Corrade ##
7 ## and the "download" Corrde command. ## 7 ## and the "download" Corrde command. ##
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   16  
17 ########################################################################### 17 ###########################################################################
18 ## INTERNALS ## 18 ## INTERNALS ##
19 ########################################################################### 19 ###########################################################################
20   20  
21 if(!isset($_POST['uuid'])) return; 21 if(!isset($_POST['uuid'])) return;
22 $uuid = $_POST['uuid']; 22 $uuid = $_POST['uuid'];
23   23  
24 #### 24 ####
25 # I. Download the map image as a PNG file. 25 # I. Download the map image as a PNG file.
26 $params = array( 26 $params = array(
27 'command' => 'download', 27 'command' => 'download',
28 'group' => $GROUP, 28 'group' => $GROUP,
29 'password' => $PASSWORD, 29 'password' => $PASSWORD,
30 'item' => $uuid, 30 'item' => $uuid,
31 'type' => 'Texture', 31 'type' => 'Texture',
32 'format' => 'Png' 32 'format' => 'Png'
33 ); 33 );
34 array_walk($params, 34 array_walk($params,
35 function(&$value, $key) { 35 function(&$value, $key) {
36 $value = rawurlencode($key)."=".rawurlencode($value); 36 $value = rawurlencode($key)."=".rawurlencode($value);
37 } 37 }
38 ); 38 );
39 $postvars = implode('&', $params); 39 $postvars = implode('&', $params);
40 if (!($curl = curl_init())) { 40 if (!($curl = curl_init())) {
41 print 0; 41 print 0;
42 return; 42 return;
43 } 43 }
44 curl_setopt($curl, CURLOPT_URL, $URL); 44 curl_setopt($curl, CURLOPT_URL, $URL);
45 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 45 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
46 curl_setopt($curl, CURLOPT_POST, true); 46 curl_setopt($curl, CURLOPT_POST, true);
47 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 47 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
48 $return = curl_exec($curl); 48 $return = curl_exec($curl);
49 curl_close($curl); 49 curl_close($curl);
50   50  
51 $success = urldecode( 51 $success = urldecode(
52 wasKeyValueGet( 52 wasKeyValueGet(
53 "success", 53 "success",
54 $return 54 $return
55 ) 55 )
56 ); 56 );
57   57  
58 if($success == 'False') { 58 if($success == 'False') {
59 echo 'Unable to download texture: '.urldecode( 59 echo 'Unable to download texture: '.urldecode(
60 wasKeyValueGet( 60 wasKeyValueGet(
61 "success", 61 "success",
62 $return 62 $return
63 ) 63 )
64 ); 64 );
65 die; 65 die;
66 } 66 }
-   67  
67   68  
68 #### 69 ####
69 # II. Convert the image data to a PNG of size 512x512 70 # II. Convert the image data to a PNG of size 512x512
70 $im = imagescale( 71 $im = imagescale(
71 imagecreatefromstring( 72 imagecreatefromstring(
72 base64_decode( 73 base64_decode(
73 rawurldecode( 74 rawurldecode(
74 wasKeyValueGet( 75 wasKeyValueGet(
75 "data", 76 "data",
76 $return 77 $return
77 ) 78 )
78 ) 79 )
79 ) 80 )
80 ), 81 ),
81 512, 82 512,
82 512 83 512
83 ); 84 );
84   85  
85 #### 86 ####
86 # III. Output the Base64 encoded image for AJAX. 87 # III. Output the Base64 encoded image for AJAX.
87 ob_start(); 88 ob_start();
88 imagepng($im); 89 imagepng($im);
89 $png = ob_get_contents(); 90 $png = ob_get_contents();
90 imagedestroy($im); 91 imagedestroy($im);
91 ob_end_clean(); 92 ob_end_clean();
92   93  
93 echo base64_encode($png); 94 echo base64_encode($png);
94   95  
95 ?> 96 ?>
96   97  
97   98