-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathonline.php
executable file
·144 lines (142 loc) · 5.07 KB
/
online.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
session_start();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHP TMX Map Viewer<?php if(array_key_exists('ref',$_REQUEST)) print(' - '.$_REQUEST['ref']); ?></title>
</head>
<body>
<?php
$map_url=array(
'tmw'=>'https://api.github.com/repos/themanaworld/tmwa-client-data/contents/maps',
'evol'=>'https://api.github.com/repos/EvolOnline/clientdata-beta/contents/maps',
'tales'=>'https://api.github.com/repos/tales/sourceoftales/contents/maps',
'elmlor'=>'https://api.github.com/repos/KaneHart/Elmlor-Client-Data/contents/maps',
'lof'=>'https://api.github.com/repos/landoffire/lof-tmwa-client-data/contents/maps',
'lof-newworld'=>'https://api.github.com/repos/landoffire/lof-newworld/contents/client-data/maps',
'stendhal'=>'http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/tiled/',
);
$github=array('tmw','evol','tales','elmlor','lof','lof-newworld');
$viewvc=array('stendhal');
if(!array_key_exists('ref',$_REQUEST)) {
?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<select name="ref">
<option value="tmw">The Mana World</option>
<option value="evol">Evol Online</option>
<option value="tales">Source of Tales</option>
<option value="lof">Land of Fire</option>
<option value="lof-newworld">Land of Fire - New World</option>
<option value="elmlor">Elmlor</option>
<option value="stendhal">Stendhal</option>
</select>
<input type="submit" value="Valider"/>
</form><?php
}
elseif(!array_key_exists('map',$_REQUEST)) {
?><form action="viewer_part_ui.php" method="GET">
<input type="hidden" name="called_from" value="script"/>
<input type="hidden" name="choice" value="url"/>
<input type="hidden" name="ref" value="<?php echo $_REQUEST['ref']; ?>"/>
<select name="url">
<?php
//$data=file_get_contents($map_url[$_REQUEST['ref']]);
$opts=array(
'http'=>array(
'user_agent'=>'Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0',
),
'ssl'=>array(
'allow_self_signed'=>true,
),
);
$ctx = stream_context_create($opts);
if(file_exists($_REQUEST['ref'].'.htm') && (!array_key_exists('force',$_REQUEST) || $_REQUEST['force']!=='1') ) {
require($_REQUEST['ref'].'.htm');
}
else if(in_array($_REQUEST['ref'], $github)) {
$data=file_get_contents($map_url[$_REQUEST['ref']],false,$ctx);
ob_start();
$ar=json_decode($data, true);
$dirs=array();
foreach($ar as $entry) {
//var_dump($entry);die();
if(substr($entry['name'],-4)=='.tmx') {
echo '<option value="'.$entry['path'].'">'.$entry['path'].'</option>'."\r\n";
}
else if($entry['type']=='dir') {
$dirs[]=$entry['url'];
}
}
foreach($dirs as $dir) {
$data=file_get_contents($dir,false,$ctx);
$ar=json_decode($data, true);
foreach($ar as $entry) {
//var_dump($entry);die();
if(substr($entry['name'],-4)=='.tmx') {
echo '<option value="'.$entry['path'].'">'.$entry['path'].'</option>'."\r\n";
}
}
}
$data=ob_get_contents();
ob_end_flush();
file_put_contents($_REQUEST['ref'].'.htm', $data);
}
elseif(in_array($_REQUEST['ref'], $viewvc)) {
$data=file_get_contents($map_url[$_REQUEST['ref']],false,$ctx);
ob_start();
function filter_dir_1($dir) {
return ($dir==='world');
}
function filter_dir_2($dir) {
return ($dir==='interiors' || substr($dir,0,6)=='Level ');
}
$dirs=array();
$files=array();
$res=preg_match_all('#<a name="([^"]+)" href="([^"]+)" title="View directory contents">#', $data, $subdirs, PREG_SET_ORDER);
foreach($subdirs as $dir) {
if(filter_dir_1($dir[1])) {
$data2=file_get_contents($map_url[$_REQUEST['ref']].$dir[1].'/',false,$ctx);
$res2=preg_match_all('#<a name="([^"]+)" href="([^"]+)" title="View file revision log">#', $data2, $files2, PREG_SET_ORDER);
foreach($files2 as $file) {
if(substr($file[1], -4)==='.tmx') {
$files[]=$dir[1].'/'.$file[1];
}
}
}
elseif(filter_dir_2($dir[1])) {
$data2=file_get_contents($map_url[$_REQUEST['ref']].$dir[1].'/',false,$ctx);
$res=preg_match_all('#<a name="([^"]+)" href="([^"]+)" title="View directory contents">#', $data2, $subdirs2, PREG_SET_ORDER);
foreach($subdirs2 as $dir2) {
$data3=file_get_contents($map_url[$_REQUEST['ref']].$dir[1].'/'.$dir2[1].'/',false,$ctx);
$res=preg_match_all('#<a name="([^"]+)" href="([^"]+)" title="View file revision log">#', $data3, $subdirs3, PREG_SET_ORDER);
foreach($subdirs3 as $file) {
if(substr($file[1], -4)==='.tmx') {
$files[]=$dir[1].'/'.$dir2[1].'/'.$file[1];
}
}
}
}
}
$res=preg_match_all('#<a name="([^"]+)" href="([^"]+)" title="View file revision log">#', $data, $dfiles, PREG_SET_ORDER);
foreach($dfiles as $file) {
if(substr($file[1], -4)==='.tmx') {
$files[]=$file[1];
}
}
foreach($files as $file) {
echo '<option value="'.$file.'">'.$file.'</option>'."\r\n";
}
$data=ob_get_contents();
ob_end_flush();
file_put_contents($_REQUEST['ref'].'.htm', $data);
}
else {
echo '<option value="">Work in Progress</option>'."\r\n";
}
?></select>
<input type="submit" value="Valider"/>
</form><?php
}
?>
</body>
</html>