corrade-http-templates – Diff between revs 15 and 72

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 15 Rev 72
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 sound using Corrade ## 6 ## This is a script that can be used to download a sound using Corrade ##
7 ## and the "download" Corrde command. ## 7 ## and the "download" Corrde command. ##
8 ########################################################################### 8 ###########################################################################
9   9  
10 if(!isset($_POST['uuid'])) return; 10 if(!isset($_POST['uuid'])) return;
11   11  
12 $uuid = $_POST['uuid']; 12 $uuid = $_POST['uuid'];
13   13  
14 ########################################################################### 14 ###########################################################################
15 ## CONFIGURATION ## 15 ## CONFIGURATION ##
16 ########################################################################### 16 ###########################################################################
17   17  
18 require_once('config.php'); 18 require_once('config.php');
19 require_once('functions.php'); 19 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
-   20 require_once('vendor/was/utilities/src/collections/arrays/arrays.php');
20   21  
21 ########################################################################### 22 ###########################################################################
22 ## INTERNALS ## 23 ## INTERNALS ##
23 ########################################################################### 24 ###########################################################################
24   25  
25   26  
26 #### 27 ####
27 # I. Resolve the inventory UUID to an asset UUID. 28 # I. Resolve the inventory UUID to an asset UUID.
28 $params = array( 29 $params = array(
29 'command' => 'getinventorydata', 30 'command' => 'getinventorydata',
30 'group' => $GROUP, 31 'group' => $GROUP,
31 'password' => $PASSWORD, 32 'password' => $PASSWORD,
32 'item' => $uuid, 33 'item' => $uuid,
33 'data' => 'AssetUUID' 34 'data' => 'AssetUUID'
34 ); 35 );
35 array_walk($params, 36 array_walk($params,
36 function(&$value, $key) { 37 function(&$value, $key) {
37 $value = rawurlencode($key)."=".rawurlencode($value); 38 $value = rawurlencode($key)."=".rawurlencode($value);
38 } 39 }
39 ); 40 );
40 $postvars = implode('&', $params); 41 $postvars = implode('&', $params);
41 if (!($curl = curl_init())) { 42 if (!($curl = curl_init())) {
42 print 0; 43 print 0;
43 return; 44 return;
44 } 45 }
45 curl_setopt($curl, CURLOPT_URL, $URL); 46 curl_setopt($curl, CURLOPT_URL, $URL);
46 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
47 curl_setopt($curl, CURLOPT_POST, true); 48 curl_setopt($curl, CURLOPT_POST, true);
48 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
49 curl_setopt($curl, CURLOPT_ENCODING, true); 50 curl_setopt($curl, CURLOPT_ENCODING, true);
50 $result = curl_exec($curl); 51 $result = curl_exec($curl);
51 curl_close($curl); 52 curl_close($curl);
52   53  
53 $success = urldecode( 54 $success = urldecode(
54 wasKeyValueGet( 55 wasKeyValueGet(
55 "success", 56 "success",
56 $result 57 $result
57 ) 58 )
58 ); 59 );
59   60  
60 if($success == 'False') { 61 if($success == 'False') {
61 echo 'Unable to get inventory UUID: '.urldecode( 62 echo 'Unable to get inventory UUID: '.urldecode(
62 wasKeyValueGet( 63 wasKeyValueGet(
63 "error", 64 "error",
64 $result 65 $result
65 ) 66 )
66 ); 67 );
67 die; 68 die;
68 } 69 }
69   70  
70 $data = str_getcsv( 71 $data = str_getcsv(
71 urldecode( 72 urldecode(
72 wasKeyValueGet( 73 wasKeyValueGet(
73 "data", 74 "data",
74 $result 75 $result
75 ) 76 )
76 ) 77 )
77 ); 78 );
78   79  
79 $data = array_combine( 80 $data = array_combine(
80 wasArrayStride( 81 wasArrayStride(
81 $data, 82 $data,
82 2 83 2
83 ), 84 ),
84 wasArrayStride( 85 wasArrayStride(
85 array_slice( 86 array_slice(
86 $data, 87 $data,
87 1 88 1
88 ), 89 ),
89 2 90 2
90 ) 91 )
91 ); 92 );
92   93  
93 if(!trim($data['AssetUUID'])) { 94 if(!trim($data['AssetUUID'])) {
94 echo 'Could not retrieve asset UUID'; 95 echo 'Could not retrieve asset UUID';
95 die; 96 die;
96 } 97 }
97   98  
98 #### 99 ####
99 # II. Download the sound as an MP3 file for HTML5 compatiblity. 100 # II. Download the sound as an MP3 file for HTML5 compatiblity.
100 $params = array( 101 $params = array(
101 'command' => 'download', 102 'command' => 'download',
102 'group' => $GROUP, 103 'group' => $GROUP,
103 'password' => $PASSWORD, 104 'password' => $PASSWORD,
104 'item' => $data['AssetUUID'], 105 'item' => $data['AssetUUID'],
105 'format' => 'mp3', 106 'format' => 'mp3',
106 'type' => 'Sound' 107 'type' => 'Sound'
107 ); 108 );
108 array_walk($params, 109 array_walk($params,
109 function(&$value, $key) { 110 function(&$value, $key) {
110 $value = rawurlencode($key)."=".rawurlencode($value); 111 $value = rawurlencode($key)."=".rawurlencode($value);
111 } 112 }
112 ); 113 );
113 $postvars = implode('&', $params); 114 $postvars = implode('&', $params);
114 if (!($curl = curl_init())) { 115 if (!($curl = curl_init())) {
115 print 0; 116 print 0;
116 return; 117 return;
117 } 118 }
118 curl_setopt($curl, CURLOPT_URL, $URL); 119 curl_setopt($curl, CURLOPT_URL, $URL);
119 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 120 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
120 curl_setopt($curl, CURLOPT_POST, true); 121 curl_setopt($curl, CURLOPT_POST, true);
121 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 122 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
122 curl_setopt($curl, CURLOPT_ENCODING, true); 123 curl_setopt($curl, CURLOPT_ENCODING, true);
123 $result = curl_exec($curl); 124 $result = curl_exec($curl);
124 curl_close($curl); 125 curl_close($curl);
125   126  
126 $success = urldecode( 127 $success = urldecode(
127 wasKeyValueGet( 128 wasKeyValueGet(
128 "success", 129 "success",
129 $result 130 $result
130 ) 131 )
131 ); 132 );
132   133  
133 if($success == 'False') { 134 if($success == 'False') {
134 echo 'Unable to download sound: '.urldecode( 135 echo 'Unable to download sound: '.urldecode(
135 wasKeyValueGet( 136 wasKeyValueGet(
136 "error", 137 "error",
137 $result 138 $result
138 ) 139 )
139 ); 140 );
140 die; 141 die;
141 } 142 }
142   143  
143 #### 144 ####
144 # III. Output the Base64 encoded data. 145 # III. Output the Base64 encoded data.
145 echo urldecode( 146 echo urldecode(
146 wasKeyValueGet( 147 wasKeyValueGet(
147 "data", 148 "data",
148 $result 149 $result
149 ) 150 )
150 ); 151 );
151   152  
152 ?> 153 ?>
153   154  
154   155