For those using the Treeview plugin: PHP directory builder

For those using the Treeview plugin: PHP directory builder

Drop me a thanks if you find it any good and you'll make me happy!
  $dir_id = if of the whole structure (the one you'll call in you jQuery)
  $dir_class...
  $path is the path to scan
  $extension is a filter. I used it to find all my PHP files for instance
  $file_on_click_event. I give you 1 guess
  1. function BuildFileList($dir_id, $dir_class = "filetree", $path="", $extension="", $file_on_click_event=""){
  2.         if(empty($path))$path    =  $_SERVER['DOCUMENT_ROOT'];
  3.         function _BuildFileList($path, $extension, $file_on_click_event=""){
  4. /*******************************************************************************
  5. *
  6. *        Sets events and a bit of initialision
  7. *
  8. ******************************************************************************/
  9.                 $list        = "";
  10.                 $dir_handle = @opendir($path) or die("Unable to open $path");

  11.                 while (false !== ($file = readdir($dir_handle))) {

  12. /*******************************************************************************

  13. *

  14. *        It's a directory! Mainly adds the folder header and does a recursion

  15. *

  16. *        **** WILL NOT INCLUDE SVN directories ****

  17. *

  18. ******************************************************************************/

  19.                         if(is_dir("$path/$file")){

  20.                                 if(".."!=$file&&"."!=$file&&".svn"!=$file){

  21.                                         $list        .=        "<li class='closed'>".

  22.                                                                 "<span class='folder'>$file</span>".

  23.                                                                 _BuildFileList("$path/$file", $extension, $file_on_click_event).

  24.                                                                 "</li>";

  25.                                 }

  26.                         }else{

  27. /*******************************************************************************

  28. *
  29. *        It's a file. Appends
  30. *
  31. ******************************************************************************/

  32.                                 if(empty($extension)){

  33.                                         $list    .= "<li><span class='file' onclick='$file_on_click_event' style='cursor:pointer;'>$file</span></li>\n";
  34.                                 }else{
  35.                                         $path_parts = pathinfo("$path/$file");
  36.                                         if(isset($path_parts["extension"])){
  37.                                                 if($extension==$path_parts["extension"]){
  38.                                                         $list        .= "<li><span class='file' onclick='$file_on_click_event' style='cursor:pointer;'>$file</span></li>\n";

  39.                                                 }
  40.                                         }

  41.                                 }
  42.                         }

  43.                 }
  44.                 closedir($dir_handle);
  45.                 return "<ul>$list</ul>";
  46.         }

  47.         $content    = _BuildFileList($path, $extension, $file_on_click_event);

  48.         return "<ul id='$dir_id' class='$dir_class'><li>$content</li></ul>";

  49. }