Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: file_listing.php,v 1.4 2006/01/17 17:02:30 cybot_tm Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 // Functions for listing directories
5  
6 /**
7 * Returns array of filtered file names
8 *
9 * @param string directory to list
10 * @param string regullar expression to match files
11 * @returns array sorted file list on success, FALSE on failure
12 */
13 function PMA_getDirContent($dir, $expression = '')
14 {
15 if ($handle = @opendir($dir)) {
16 $result = array();
17 if (substr($dir, -1) != '/') {
18 $dir .= '/';
19 }
20 while ($file = @readdir($handle)) {
21 if (is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
22 $result[] = $file;
23 }
24 }
25 @closedir($handle);
26 asort($result);
27 return $result;
28 } else {
29 return FALSE;
30 }
31 }
32  
33 /**
34 * Returns options of filtered file names
35 *
36 * @param string directory to list
37 * @param string regullar expression to match files
38 * @param string currently active choice
39 * @returns array sorted file list on success, FALSE on failure
40 */
41 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
42 {
43 $list = PMA_getDirContent($dir, $extensions);
44 if ($list === FALSE) {
45 return FALSE;
46 }
47 $result = '';
48 foreach ($list as $key => $val) {
49 $result .= '<option value="'. htmlspecialchars($val) . '"';
50 if ($val == $active) {
51 $result .= ' selected="selected"';
52 }
53 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
54 }
55 return $result;
56 }
57  
58 /**
59 * Get currently supported decompressions.
60 *
61 * @returns string | separated list of extensions usable in PMA_getDirContent
62 */
63 function PMA_supportedDecompressions()
64 {
65 global $cfg;
66  
67 $compressions = '';
68  
69 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
70 if (!empty($compressions)) {
71 $compressions .= '|';
72 }
73 $compressions .= 'gz';
74 }
75 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
76 if (!empty($compressions)) {
77 $compressions .= '|';
78 }
79 $compressions .= 'bz2';
80 }
81 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
82 if (!empty($compressions)) {
83 $compressions .= '|';
84 }
85 $compressions .= 'zip';
86 }
87  
88 return $compressions;
89 }