forked from pmt-mcpe-me/plugingen-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewSrc.php
170 lines (167 loc) · 3.84 KB
/
viewSrc.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
use pg\lib\Generator;
define("ACCEPT_SUBPATH", true);
include_once dirname(__FILE__) . "/utils.php";
$proj = forceProject();
$gen = new Generator($proj);
$gen->generate();
$files = $gen->files;
if(!isset($_SERVER["PATH_INFO"])){
redirect($_SERVER["SCRIPT_NAME"] . "/");
}
$path = preg_replace("#[/\\\\]{2,}#", "/", $_SERVER["PATH_INFO"]);
?>
<html>
<head>
<title>Source Viewer | PocketMine Plugin Generator</title>
<?= INCLUDE_JQUERY ?>
<!--suppress HtmlUnknownTarget -->
<link rel="stylesheet" type="text/css" href="<?= $_SERVER["SCRIPT_NAME"] ?>/../style/normal.css">
<?php
if($path === "/"){
goto listPath;
}else{
$path = rtrim($path, "/");
if(isset($files[$path])){
goto dispFile;
}else{
foreach(array_keys($files) as $k){
if(strtolower(substr($k, 0, strlen($path) + 1)) === strtolower("$path/")){
$path .= "/";
goto listPath;
}
}
}
}
http_response_code(404);
?>
</head>
<body>
<h1 class="error">Error</h1>
<hr>
<p>That file/directory (<code class="code"><?= $path ?></code>) could not be located. Go <a href="<?= $_SERVER["SCRIPT_NAME"] ?>/">here</a> to view the root directory.</p>
<hr>
<p>
<button onclick="location = '../';" class="button">Back</button>
</p>
</body>
</html>
<?php
return;
listPath:
?>
<!--suppress HtmlUnknownTarget -->
<link rel="stylesheet" type="text/css" href="<?= $_SERVER["SCRIPT_NAME"] ?>/../style/dirView.css">
<?= "</head>" ?>
<body>
<h3>Index of
<?php
$myName = $_SERVER["SCRIPT_NAME"];
echo "<a href='$myName'>{$proj->getDesc()->getName()}</a> ";
foreach(explode("/", substr($path, 1)) as $part){
if($part === ""){
continue;
}
echo '/ <a href="';
$myName .= "/";
$myName .= urlencode($part);
echo $myName;
echo '">';
echo htmlspecialchars($part);
echo '</a> ';
}
?>/
</h3>
<ul>
<?php
if($path !== "/"){
echo "<li><a href='";
echo rtrim($_SERVER["REQUEST_URI"], "/") . "/..";
echo "'>..</a>";
}
$ok = [];
foreach(array_keys($files) as $file){
if(strtolower(substr($file, 0, strlen($path))) === strtolower($path)){
$ok[] = ltrim(substr($file, strlen($path)), "/");
}
}
sort($ok, SORT_NATURAL);
$internalDir = [];
foreach($ok as $f){
$pointer =& $internalDir;
$exp = explode("/", $f);
foreach($exp as $i => $part){
if(!isset($pointer[$part])){
if(!isset($exp[$i + 1])){ // is filename
$pointer[$part] = true;
break;
}
else{ // is dirname
$pointer[$part] = [];
}
}
$pointer =& $pointer[$part];
}
}
$myName = $_SERVER["SCRIPT_NAME"] . htmlspecialchars($path);
foreach($internalDir as $name => $dir){
if($dir === true){
echo "<li><a href='$myName$name'>$name</a></li>";
}
else{
while(is_array($dir) and count($dir) === 1){
$n = array_keys($dir)[0];
if($dir === true){
break;
}
$name .= "/" . $n;
$dir = $dir[$n];
}
?>
<li><a href='<?= $myName . $name ?>'><?= $name . (isset($gen->files[$path . $name]) ? "" : "/") ?></a></li>
<?php
}
}
?>
</ul>
<hr>
<p>
<button onclick="location = '../';" class="button">Back</button>
</p>
</body>
<?php
return;
dispFile:
?>
<!--suppress HtmlUnknownTarget -->
<link rel="stylesheet" type="text/css" href="<?= $_SERVER["SCRIPT_NAME"] ?>/../style/sourceView.css">
<?= "</head>" ?>
<body>
<h3>
<?php
$myName = $_SERVER["SCRIPT_NAME"];
echo "<a href='$myName'>{$proj->getDesc()->getName()}</a> ";
foreach(explode("/", substr($path, 1)) as $part){
echo '/ <a href="';
$myName .= "/";
$myName .= urlencode($part);
echo $myName;
echo '">';
echo htmlspecialchars($part);
echo '</a> ';
}
?>
</h3>
<div class="main-source">
<?php
$indent = 4;
echo preg_replace("#([\r\n]|(\r\n))#", "<br>", str_replace(["\t"], [str_repeat(" ", $indent)], htmlspecialchars(str_replace(["\r\n"], ["\n"], $files[$path]))));
?>
</div>
<hr>
<p>
<button onclick="location = '../';" class="button">Back</button>
</p>
</body>
<?php
echo "</html>";