-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
106 lines (72 loc) · 2.18 KB
/
functions.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
<?php
/*
* Copyright (c) Codiad, Rafasashi, distributed
* as-is and without warranty under the MIT License.
* See http://opensource.org/licenses/MIT for more information.
* This information must remain intact.
*/
function getWorkspacePath($path, $error='Invalid path'){
//Security check
if (!Common::checkPath($path)) {
die($error);
}
if (strpos($path, "/") === 0) {
//Unix absolute path
return $path;
}
if (strpos($path, ":/") !== false) {
//Windows absolute path
return $path;
}
if (strpos($path, ":\\") !== false) {
//Windows absolute path
return $path;
}
return WORKSPACE . "/" . $path;
}
function getArchiveTree($level=1){
$tree=[];
if(isset($_GET['path'])){
//TODO: Common::checkPath($path) return false...
$source = getWorkspacePath($_GET['path']);
//$source = WORKSPACE . "/" . $_GET['path'];
if(file_exists($source)){
$source_info=pathinfo($source);
if(isset($source_info['extension'])&&!empty($source_info['extension'])){
$des = dirname($source);
if($source_info['extension']=='zip'){
if(class_exists('ZipArchive') && $zip = new ZipArchive) {
if($res = $zip->open($source)){
for ($i = 0; $i < $zip->numFiles; $i++) {
$name = $zip->getNameIndex($i);
$path = $name;
$count=substr_count($path, '/');
if($count > $level){
continue;
}
$tree[$name]=$path;
}
$zip->close();
}
}
}
elseif($source_info['extension']=='tar') {
if(class_exists('PharData') && $tar = new PharData($source)) {
//TODO: get tar tree
}
}
elseif($source_info['extension']=='rar') {
if(class_exists('rar_open') && $rar = new rar_open) {
if($res = $rar->open($source)){
$entries = rar_list($res);
//TODO: get rar tree
$rar->close();
}
}
}
}
}
}
return $tree;
}
?>