\n"); } ///////////////////////////// // Support functions function make_blank($path) { global $template_file, $template_file_default; $template_file = $template_file_default; return ""; } //this makes the tree view, and starts at the path before the $base_path, and then goes to $base_path, //then through the directory handlers found from then on down the tree function make_tree($target_path) { global $template_file, $base_path, $template_file_tree; $template_file = $template_file_tree; return recurse_tree($target_path, $base_path); } function recurse_tree($target_path, $current_path) { global $directory_separator, $template_file, $base_path, $template_file_tree; static $branch_number = 0; $out = ""; $on_path = starts_with($target_path.$directory_separator, $current_path.$directory_separator); $root = ($current_path == $base_path); if($current_path == 'Poxin') $inroot = 11; else $inroot = 0; if(($directory_handler = get_handler($current_path, "directory")) != false) { if(!$root) $out .= $directory_handler->make_tree_header(); if(!$root) { //print this directory's label $anchor = "branch".$branch_number; $branch_number++; $link = "chunky.php?request=tree&path=".urlencode($current_path)."#".$anchor.""; $other_attributes = " name=$anchor"; $directory_name = get_last_name_from_path($current_path); $out .= $directory_handler->make_tree_item_header(); $out .= $directory_handler->make_tree_label($directory_name, $link, $other_attributes, $current_path, $base_path, $inroot); $out .= $directory_handler->make_tree_item_footer(); } if($on_path) { if(!$root) $out .= $directory_handler->make_tree_item_header(); //then this dir we're looking at is on the opened path, so expand it $selected_list = $directory_handler->make_tree_selection($current_path); //allow subjective filtering for($x = 0; $x < count($selected_list); $x++) $out .= recurse_tree($target_path, $current_path . $directory_separator . $selected_list[$x]); $out .= $directory_handler->make_tree_header(); $out .= $directory_handler->make_tree_item_header(); $out .= "\t\t
\n
\n"; $out .= "\t\t
\n"; $out .= make_branch($current_path, $directory_handler); $out .= "\t\t
\n"; $out .= "\t\t
\n"; $out .= $directory_handler->make_tree_item_footer(); $out .= $directory_handler->make_tree_footer(); // $out .= "
\n"; if(!$root) $out .= $directory_handler->make_tree_item_footer(); } if(!$root) $out .= $directory_handler->make_tree_footer(); } else { $out .= "Error, applicable handler for type \"directory\" not found!
\n"; } return $out; } function make_branch($path, $directory_handler) { global $directory_separator, $handler_objects; $out = ""; $path = cut_off_tail($path, $directory_separator); //make sure there is no pesky / on the end of the path $current_directory = get_directory_from_path($path); //grab the list of items to show $display_selection = $directory_handler->make_branch_selection($path); if(count($display_selection) > 0) $cur_type = strtolower(get_file_type($display_selection[0])); else $cur_type = ""; for($x = 0; $x < count($display_selection); $x++) { $last_type = $cur_type; $cur_file = $display_selection[$x]; $cur_type = strtolower(get_file_type($cur_file)); $next_file = $display_selection[($x+1)%count($display_selection)]; if(($cur_type_handler = get_handler($current_directory, $cur_type)) != false) //if one's found, then: { $out .= $directory_handler->make_leaf_in_branch_header($path, $x); $out .= $cur_type_handler->make_branch_display($path . $directory_separator . $cur_file, $next_file); $out .= $directory_handler->make_leaf_in_branch_footer($path, $x, $cur_type, $last_type); } else { $out .= "Error, applicable handler for type \"" . $cur_type . "\" not found, starting at directory \"" . $path . "\"
\n"; } } return $out; } function make_leaf($path) { global $handler_objects, $directory_separator, $template_file, $template_file_leaf_default; $out = ""; $current_directory = get_directory_from_path($path); $path = cut_off_tail($path, $directory_separator); $leaf_type = strtolower(get_file_type($path)); //determine the correct directory handler to use, and load it if(($directory_handler = get_handler($current_directory, "directory")) != false) { //grab the list of items being showed in the series this one's in //this will be be used to find the next item in case we want to link to it or whatever $display_selection = $directory_handler->make_branch_selection(get_directory_from_path($path)); //find the index in the list that this one is $index = -1; $curr_file = get_last_name_from_path($path); for($x = 0; $x < count($display_selection); $x++) if($curr_file == $display_selection[$x]) $index = $x; if($index < 0) { $out .= "Error, file not found in list to show...
\n"; $next_path = $path; $prev_path = $path; } else { //use that to get the next path. $next_file = $display_selection[($index+1)%count($display_selection)]; $next_path = get_directory_containing($path) . $directory_separator . $next_file; //and prev $prev_file = $display_selection[($index+count($display_selection)-1)%count($display_selection)]; $prev_path = get_directory_containing($path) . $directory_separator . $prev_file; } if(is_dir($path)) { $out .= "Error, cannot view a directory (\"" . $path . "\") as a leaf.
\n"; } else { if(($leaf_handler = get_handler($current_directory, $leaf_type)) != false) { $template_file = search_backwards_for_file($current_directory, $leaf_handler->template_file_leaf, $leaf_handler->template_file_leaf); if(!$template_file) { $out .= "Warning: couldn't find template file \"".$leaf_handler->template_file_leaf."\", using default.
\n"; $template_file = $template_file_leaf_default; } $out .= $leaf_handler->make_leaf_display($path, $next_path, $prev_path); } else { $out .= "Error, applicable handler for type \"" . $leaf_type . "\" not found, starting at directory \"" . get_directory_from_path($path) . "\"
\n"; } } } else { $out .= "Error, applicable handler for directory not found, starting at directory \"" . $current_directory . "\"
\n"; } return $out; } ///////////////////////////// // Finished, now template the data and print. output_template_filled_with_data(); ?>