package Base::Menu; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw(push_file print_menu); use Cwd; use File::Basename; use File::Find; use HTML::Entities qw(encode_entities); use List::Util qw(first); use URI::Encode qw(uri_encode); use lib ".."; use Base::Roots qw(file_text); use Base::Nifty qw(line my_sort); my $full_path = cwd.'/'.basename($0); my $current_directory = cwd; #If I want to color code my file names by type, this is what I use. sub link_color { my ($var) = @_; my $color = "000"; $color = "f00" if ($var =~ m!pl$!); $color = "900" if ($var =~ m!pm$!); $color = "00f" if ($var =~ m!html$!); $color = "009" if ($var =~ m!shtml$!); $color = "003" if ($var =~ m!svg$!); $color = "060" if ($var =~ m!css$!); $color = "0f0" if ($var =~ m!csv$!); $color = "090" if ($var =~ m!txt$!); $color = "990" if ($var =~ m!zip$!); $color = "099" if ($var =~ m!js$!); $color = "c33" if ($var =~ m!pdf$!); $color = "939" if ($var =~ m!wav$!); $color = "909" if ($var =~ m!(gif|ico|jpg|png)$!); $color = "696" if ($var =~ m!xls$!); return qq( style="color:#$color"); } #push_file and print_menu are the backbones of printing my directories and files in an html list. #written by simcop2387 in the #perlcafe on freenode. sub push_file { my $directory = shift; #get the previous directory my $file = shift; #get the file we're going to push onto the structure if ($file =~ m|/|) { #check if there are any more directories in our file name my ($newdir, $newfile) = split(m|/|, $file, 2); # split the top directory off $directory->{$newdir} = {} unless $directory->{$newdir}; #create the hash if it isn't there push_file($directory->{$newdir}, $newfile); #recurse with the file name and the directory. } else { # we have no more / in our file name, so go ahead and just add it push @{$directory->{''}}, $file; #add the file. } } sub print_menu { my ($level,$href,$dir,$link,$java,$colors) = @_; line($level,qq(