コード例 #1
0
ファイル: filetree.php プロジェクト: Galixte/uploadstyle
 public static function php_file_tree_dir($directory, $uaction, $extensions = array(), $first_call = true)
 {
     if (function_exists('scandir')) {
         $file = scandir($directory);
     } else {
         $file = php4_scandir($directory);
     }
     natcasesort($file);
     // Make directories first
     $files = $dirs = array();
     foreach ($file as $this_file) {
         if (is_dir($directory . '/' . $this_file)) {
             $dirs[] = $this_file;
         } else {
             $files[] = $this_file;
         }
     }
     $file = array_merge($dirs, $files);
     // Filter unwanted extensions
     if (!empty($extensions)) {
         foreach (array_keys($file) as $key) {
             if (!is_dir($directory . '/' . $file[$key])) {
                 $ext = substr($file[$key], strrpos($file[$key], '.') + 1);
                 if (!in_array($ext, $extensions)) {
                     unset($file[$key]);
                 }
             }
         }
     }
     if (count($file) > 2) {
         // Use 2 instead of 0 to account for . and .. directories
         $php_file_tree = '<ul';
         if ($first_call) {
             $php_file_tree .= ' class="php-file-tree"';
             $first_call = false;
         }
         $php_file_tree .= '>';
         foreach ($file as $this_file) {
             if ($this_file != '.' && $this_file != '..') {
                 if (is_dir($directory . '/' . $this_file)) {
                     // Directory
                     $php_file_tree .= '<li class="pft-directory"><span>' . htmlspecialchars($this_file) . '</span>';
                     $php_file_tree .= \filetree::php_file_tree_dir($directory . '/' . $this_file, $uaction, $extensions, false);
                     $php_file_tree .= '</li>';
                 } else {
                     // File
                     // Get extension (prepend 'ext-' to prevent invalid classes from extensions that begin with numbers)
                     $ext = 'ext-' . substr($this_file, strrpos($this_file, '.') + 1);
                     //						$link = '/adm/index.php?i=-forumhulp-upload-acp-upload_module&sid=90b2a79945e6a0c1f0b33626e9ffcffc&mode=main&file=' . $directory . '/' . urlencode($this_file);
                     $link = $uaction . '&file=' . $directory . '/' . urlencode($this_file);
                     $php_file_tree .= '<li class="pft-file ' . strtolower($ext) . (!in_array(strtolower($ext), array('ext-png', 'ext-jpg', 'ext-gif')) ? '" onclick="loadXMLDoc(\'' . $link . '\')"' : '') . ' title="' . $this_file . '"><span>' . htmlspecialchars($this_file) . '</span></li>';
                 }
             }
         }
         $php_file_tree .= '</ul>';
     }
     return $php_file_tree;
 }