1 | <?php |
---|
2 | // /home/username/foo/public_html/ |
---|
3 | $dir = dirname(__FILE__)."/../.."; |
---|
4 | $include = '/\.(php|shtml|html|htm|shtm|cgi|txt|doc|pdf|rtf|xls|csv)$/'; |
---|
5 | $exclude = ''; |
---|
6 | $dirinclude = ''; |
---|
7 | $direxclude = '/(^|\/)[._]|htmlarea/'; // Exclude the htmlarea tree by default |
---|
8 | |
---|
9 | // New backend config data passing |
---|
10 | // if data was passed using xinha_pass_to_backend() we extract and use it |
---|
11 | // as the items above |
---|
12 | require_once(realpath(dirname(__FILE__) . '/../../contrib/php-xinha.php')); |
---|
13 | if($passed_data = xinha_read_passed_data()) |
---|
14 | { |
---|
15 | extract($passed_data); |
---|
16 | } |
---|
17 | |
---|
18 | // Old deprecated backend config data passing |
---|
19 | // not described because you shouldn't use it. |
---|
20 | //------------------------------------------------------------------------ |
---|
21 | $hash = ''; |
---|
22 | foreach(explode(',', 'dir,include,exclude,dirinclude,direxclude') as $k) |
---|
23 | { |
---|
24 | if(isset($_REQUEST[$k])) |
---|
25 | { |
---|
26 | if(get_magic_quotes_gpc()) |
---|
27 | { |
---|
28 | $_REQUEST[$k] = stripslashes($_REQUEST[$k]); |
---|
29 | } |
---|
30 | $hash .= $k . '=' . $_REQUEST[$k]; |
---|
31 | $$k = $_REQUEST[$k]; |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | if($hash) |
---|
36 | { |
---|
37 | session_start(); |
---|
38 | if(!isset($_SESSION[sha1($hash)])) |
---|
39 | { |
---|
40 | ?> |
---|
41 | [ ]; |
---|
42 | <?php |
---|
43 | exit; |
---|
44 | } |
---|
45 | } |
---|
46 | //------------------------------------------------------------------------ |
---|
47 | |
---|
48 | |
---|
49 | function scan($dir, $durl = '') |
---|
50 | { |
---|
51 | global $include, $exclude, $dirinclude, $direxclude; |
---|
52 | static $seen = array(); |
---|
53 | |
---|
54 | $files = array(); |
---|
55 | |
---|
56 | $dir = realpath($dir); |
---|
57 | if(isset($seen[$dir])) |
---|
58 | { |
---|
59 | return $files; |
---|
60 | } |
---|
61 | $seen[$dir] = TRUE; |
---|
62 | $dh = @opendir($dir); |
---|
63 | |
---|
64 | |
---|
65 | while($dh && ($file = readdir($dh))) |
---|
66 | { |
---|
67 | if($file !== '.' && $file !== '..') |
---|
68 | { |
---|
69 | $path = realpath($dir . '/' . $file); |
---|
70 | $url = $durl . '/' . $file; |
---|
71 | |
---|
72 | if(($dirinclude && !preg_match($dirinclude, $url)) || ($direxclude && preg_match($direxclude, $url))) continue; |
---|
73 | if(is_dir($path)) |
---|
74 | { |
---|
75 | if($subdir = scan($path, $url)) |
---|
76 | { |
---|
77 | $files[] = array('url'=>$url, 'children'=>$subdir); |
---|
78 | } |
---|
79 | } |
---|
80 | elseif(is_file($path)) |
---|
81 | { |
---|
82 | if(($include && !preg_match($include, $url)) || ($exclude && preg_match($exclude, $url))) continue; |
---|
83 | $files[] = array('url'=>$url); |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | } |
---|
88 | @closedir($dh); |
---|
89 | return dirsort($files); |
---|
90 | } |
---|
91 | |
---|
92 | function dirsort($files) |
---|
93 | { |
---|
94 | usort($files, 'dircomp'); |
---|
95 | return $files; |
---|
96 | } |
---|
97 | |
---|
98 | function dircomp($a, $b) |
---|
99 | { |
---|
100 | if(is_array($a)) $a = array_shift($a); |
---|
101 | if(is_array($b)) $b = array_shift($b); |
---|
102 | return strcmp(strtolower($a), strtolower($b)); |
---|
103 | } |
---|
104 | |
---|
105 | echo xinha_to_js(scan($dir)); |
---|
106 | ?> |
---|