forked from steppin/tagpro-map-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.php
More file actions
62 lines (62 loc) · 2.33 KB
/
test.php
File metadata and controls
62 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
header('Content-Type: text/plain;charset=UTF-8');
function user_agent($address)
{
return ($curl = curl_init($address))
&& curl_setopt($curl, CURLOPT_USERAGENT, 'RondingTagProMapEditor/1.0 (+http://map-editor.tagpro.eu)')
&& curl_setopt($curl, CURLOPT_RETURNTRANSFER, true)
? $curl : false;
}
function upload_map($address, $logic, $layout, $play)
{
global $clouds;
$sys = sys_get_temp_dir();
ignore_user_abort();
$json = tempnam($sys, 'mj');
$png = tempnam($sys, 'mp');
file_put_contents($json, $_POST['logic']);
file_put_contents($png, base64_decode($_POST['layout']));
if(($curl = user_agent($address))
&& curl_setopt($curl, CURLOPT_POST, true)
&& curl_setopt($curl, CURLOPT_POSTFIELDS, array(
$logic => new CURLFile($json, 'application/json', 'map.json'),
$layout => new CURLFile($png, 'image/png', 'map.png'))))
{
if($play)
{
if(curl_exec($curl) !== false && ($result = curl_getinfo($curl, CURLINFO_REDIRECT_URL)) !== false)
echo $result;
}
else
{
if(($result = curl_exec($curl)) !== false && ($result = json_decode($result)) && $result->success)
echo 'http://', $clouds[$_POST['cloud']], isset($result->saveurl) ? $result->saveurl : $result->url;
}
}
unlink($json);
unlink($png);
}
if(isset($_POST['logic']) && isset($_POST['layout']))
{
$servers = array(
'maptest.newcompte.fr',
'maptest2.newcompte.fr',
'maptest3.newcompte.fr',
'oceanic.newcompte.fr');
$clouds = array(
'maps.jukejuice.com',
'unfortunate-maps.jukejuice.com');
if(isset($_POST['server']) && isset($servers[$_POST['server']]))
upload_map('http://' . $servers[$_POST['server']] . '/testmap', 'logic', 'layout', true);
elseif(isset($_POST['cloud']) && isset($clouds[$_POST['cloud']]))
upload_map('http://' . $clouds[$_POST['cloud']] . '/upload', 'file[0]', 'file[1]', false);
}
elseif(isset($_POST['url']) && preg_match('#^\s*(?:http://)?((?:unfortunate-)?maps\.jukejuice\.com)/(?:show|static/previews)/(\d+)(?:\.png)?\s*$#', $_POST['url'], $matches))
{
if(($curl = user_agent('http://' . $matches[1] . '/download?mapname=map&type=json&mapid=' . $matches[2]))
&& ($json = curl_exec($curl)) !== false
&& ($curl = user_agent('http://' . $matches[1] . '/download?mapname=map&type=png&mapid=' . $matches[2]))
&& ($png = curl_exec($curl)) !== false)
echo json_encode(array('logic' => $json, 'layout' => base64_encode($png)));
}
?>