-
Notifications
You must be signed in to change notification settings - Fork 79
/
dplayer.php
445 lines (416 loc) · 12.3 KB
/
dplayer.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
/**
*
*/
//define("PASS", "123");//若要设置密码请将define()前的斜线删去
class dir{
public $dir;
public $file;
public $dirdir;
public $notex;
public $notdir;
function __construct(){
$this->notex=array("php","js","tgz");//不允许显示的后缀名文件
$this->notdir=array("a","phpmyadmin");//不允许显示的文件夹
if (isset($_GET['dir'])) {
foreach ($this->notdir as $key => $value) {
if(strtolower($_GET['dir'])==$value){
$_GET['dir']=".";
}
}
$tom=trim($_GET['dir']);
$tam=str_replace("..", ".", $tom);
$this->dir="./".$tam;
}else{
$this->dir=".";
}
}
function ex($string){
$ar=explode(".", $string);
$ex=array_pop($ar);
return strtolower($ex);
}
function open_dir(){
if(is_dir($this->dir)){
if($dh=opendir($this->dir)){
while(($file=readdir($dh))!==false){
$this->jugg($file);
}
//sort($this->file);
//sort($this->dirdir);
closedir($dh);
}
}else{
echo "error";
}
}
function jugg($jugg){
if($jugg!="."&&$jugg!=".."){
if (is_dir($this->dir."/".$jugg)) {
if(!in_array(strtolower($this->filename($jugg)), $this->notdir)){
$this->dirdir[]=$this->dir."/".$jugg;
}
}else{
$ex=$this->ex($jugg);
if(!in_array($ex, $this->notex)){
$this->file[]=$this->dir."/".$jugg;
}
}
}
}
function dirurl($dir){
$urf=substr($dir,2 );
return "?dir=".rawurlencode($urf);
}
function value($value){
$urf=substr($value,2 );
return $urf;
}
function type($file){
$ex=$this->ex($file);
switch ($ex) {
case 'png':
case 'jpg':
case 'gif':
case 'bmp':
case 'jpeg':
return "img";
break;
case 'torrent':
return "torrent";
break;
case 'mp3':
return "mp3";
break;
case 'mp4':
case 'ogg':
case 'webm':
return "video";
break;
case 'xls':
case 'xlsx':
case 'doc':
case 'docx':
case 'ppt':
case 'pptx':
return "other";
break;
case 'pdf':
return "pdf";
break;
case 'txt':
case 'json':
case 'xml':
case 'html':
case 'md':
return "text";
break;
default:
return "other";
break;
}
}
function download($file){
return "<a href=\"".$file."\" ><span class=\"glyphicon glyphicon-download-alt\"></span></a>";
}
function md5($file){
return md5_file($file);
}
function other($file){
}
function img($img){
}
function pdf($pdf){
}
function video($video){
}
function mp3($mp3){
}
function torrent($torrent){
}
function filename($file){
$ar=explode("/", $file);
return array_pop($ar);
}
function text($file){
}
function size($file){
$fz=filesize($file);
if ($fz>(1024*1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024*1024))."GB";
}elseif ($fz>(1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024))."MB";
}elseif($fz>1024){
return sprintf("%.2f",$fz/1024)."KB";
}else{
return $fz."B";
}
}
function mtime($file){
return date("Y-m-d H:i:s",filemtime($file));
}
function atime($file){
return date("Y-m-d H:i:s",fileatime($file));
}
function ctime($file){
return date("Y-m-d H:i:s",filectime($file));
}
function icon($file){
$ex=$this->ex($file);
switch ($ex) {
case 'png':
case 'jpg':
case 'gif':
case 'bmp':
case 'jpeg':
return "glyphicon glyphicon-picture";
break;
case 'torrent':
return "glyphicon glyphicon-magnet";
break;
case 'mp3':
return "glyphicon glyphicon-music";
break;
case 'mp4':
case 'ogg':
case 'webm':
return "glyphicon glyphicon-film";
break;
case 'xls':
case 'xlsx':
case 'doc':
case 'docx':
case 'ppt':
case 'pptx':
return "glyphicon glyphicon-pencil";
break;
case 'pdf':
return "glyphicon glyphicon-book";
break;
case 'txt':
case 'md':
return "glyphicon glyphicon-file";
break;
default:
return "glyphicon glyphicon-stop";
break;
}
}
function pre(){
$dir_array=explode("/", $this->dir);
$num=count($dir_array);
if($num>=2){
@array_shift($dir_array);
$url="<a class=\"text-success\" href=?>/.</a>";
$step="";
foreach ($dir_array as $key => $value) {
$step=$step.$value."/";
$url=$url."<a class=\"text-success\" href=\"?dir=".$step."\">/".$value."</a>";
}
return $url;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/dplayer/1.1.2/DPlayer.min.js"></script>
<title>Webdir-danmu</title>
<style type="text/css">
body{
background-color:#F1F1FA;
}
.container{
margin-top: 100px;
border-radius:15px;
background-color:#FFFFFF;
}
</style>
</head>
<body>
<?php
$time=time();
$server=$_SERVER['HTTP_HOST'];
$token=base64_encode($_SERVER['REMOTE_ADDR'].":".$time.":".$server);
if(defined("PASS")){
session_start();
if ($_SESSION['user']==PASS) {
}else{
if($_POST['pass']==PASS){
$_SESSION['user']=PASS;
}else{
?>
<div class="container">
<form method="POST" action="">
<div class="row">
<h1 class="text-center text-success">Webdir</h1>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="input-group">
<input type="password" name="pass" class="form-control">
<span class="input-group-btn">
<input type="submit" name="sub" value="登入" class="btn btn-danger">
</span>
</div>
</div>
</div>
</form>
<div class="row">
<span style="margin: 15px;">Powered by <a href="https://github.com/maysrp/webdir">Webdir</a></span>
</div>
</div>
<?php
return false;
}
}
}
$x=new dir();
$x->open_dir();
?>
<div class="container">
<div class="row">
<div class="col-md-1">
<a href="
<?php echo isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"" ?> "
><h2 class="btn btn-primary"><span class="glyphicon glyphicon-chevron-left " id="back"></span></h2></a>
</div>
<div class="col-md-10">
<h3>
<?php
echo $x->pre();
?> </h3>
</div>
</div>
<table class="table table-striped ">
<tr>
<th>文件名</th>
<th>大小</th>
<th>时间</th>
<th>下载</th>
</tr>
<?php
if(isset($x->dirdir)){
foreach ($x->dirdir as $key => $value) {
echo "<tr>";
echo "<td><a href=\"".$x->dirurl($value)."\"><span class=\"glyphicon glyphicon-list\"> ".$x->filename($value)."</span></a></td>";
echo "<td>目录</td>";
echo "<td>".$x->mtime($value)."</td>";
echo "<td></td>";
echo "</tr>";
}
}
if(isset($x->file)){
foreach ($x->file as $key => $value) {
echo "<tr>";
echo "<td><span class=\" click_onload ".$x->icon($value)." fileshow\" type=\"".$x->type($value)."\" value=\"".$x->value($value)."\" md5=\"".$x->md5($value)."\"> ".$x->filename($value)."</span></td>";
echo "<td>".$x->size($value)."</td>";
echo "<td>".$x->mtime($value)."</td>";
echo "<td>".$x->download($value)."</td>";
echo "</tr>";
}
}
?>
</table>
<span>Powered by <a href="https://github.com/maysrp/webdir">webdir</a></span>
</div>
<div>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="modal">
<div class="modal-dialog modal-lg">
<div class="modal-content ">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body text-center">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".fileshow").click(function(){
var type=$(this).attr("type");
var name=$(this).text();
var value=$(this).attr("value");
var md5=$(this).attr("md5");
switch(type){
case "img":
$(".modal-title").html("");
$(".modal-title").html(name);
$(".modal-body").html("");
$(".modal-body").html("<a href=\""+value+"\"><img style=\"max-width:80%;\" src=\""+value+"\"></a>");
$("#modal").modal();
break;
case "video":
case "mp3":
$(".modal-title").html("");
$(".modal-title").html(name);
$(".modal-body").html("");
$(".modal-body").html("<div id=\"player1\" class=\"dplayer\"></div>");
//$(".modal-body").html("<video width=\"80%\" autoplay controls id=\"play\" src=\""+value+"\"></video>");
$("#modal").modal();
dp = new DPlayer({
element: document.getElementById('player1'), // Optional, player element
autoplay: false, // Optional, autoplay video, not supported by mobile browsers
theme: '#FADFA3', // Optional, theme color, default: #b7daff
loop: true, // Optional, loop play music, default: true
lang: 'zh', // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language
screenshot: true, // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
hotkey: true, // Optional, binding hot key, including left right and Space, default: true
preload: 'auto', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
video: { // Required, video info
url: value, // Required, video url
pic: 'a.jpg' // Optional, music picture
},
danmaku: { // Optional, showing danmaku, ignore this option to hide danmaku
id: md5, // Required, danmaku id, NOTICE: it must be unique, can not use these in your new player: `https://api.prprpr.me/dplayer/list`
api: 'http://dm.loli.mba:1024', // Required, danmaku api
token: '<?php echo $token ?>', // Optional, danmaku token for api
maximum: 1000, // Optional, maximum quantity of danmaku IP base64
}
});
break;
case "text":
$(".modal-title").html("");
$(".modal-title").html(name);
$(".modal-body").html("");
$(".modal-body").html("<iframe width=\"80%\" height=\"600px\" src=\""+value+"\">");
$("#modal").modal();
break;
case "pdf":
$(".modal-title").html("");
$(".modal-title").html(name);
$(".modal-body").html("");
$(".modal-body").html("<iframe width=\"80%\" height=\"800px\" src=\""+value+"\">");
$("#modal").modal();
default:
}
})
$('#modal').on('hidden.bs.modal', function (e) {
if(window.dp){
dp.pause();
}
})
$(".click_onload").mouseover(function(){
$(this).addClass("text-primary");
})
$(".click_onload").mouseout(function(){
$(this).removeClass("text-primary");
})
</script>
<script type="text/javascript">
</script>
</body>
</html>