From: Rob H. <for...@us...> - 2001-12-06 23:35:55
|
Update of /cvsroot/sandweb/sandweb/lib/SandWeb In directory usw-pr-cvs1:/tmp/cvs-serv6568/lib/SandWeb Modified Files: Browse.pm Log Message: fixed a couple bugs with view/edit file functionality by making it use the File object properly ( finally ;) Index: Browse.pm =================================================================== RCS file: /cvsroot/sandweb/sandweb/lib/SandWeb/Browse.pm,v retrieving revision 1.20 retrieving revision 1.21 diff -U2 -r1.20 -r1.21 --- Browse.pm 2001/11/27 00:31:11 1.20 +++ Browse.pm 2001/12/06 23:35:51 1.21 @@ -5,4 +5,5 @@ package SandWeb::Browse; +use strict; use lib '../lib'; use SandWeb::UI; @@ -11,56 +12,57 @@ sub new { - my $class = shift; - my %args = @_; + my $class = shift; + my %args = @_; - my $self = bless { - 'username' => $args{'username'}, - 'template_dir' => $args{'template_dir'}, - 'users_dir' => $args{'users_dir'}, - }, $class; + my $self = bless { + 'username' => $args{'username'}, + 'template_dir' => $args{'template_dir'}, + 'users_dir' => $args{'users_dir'}, + }, $class; - return $self; + return $self; } sub browse { - my $self = shift; - my $path = shift; - my $progname = shift; - my $vcs_commands = shift; - my $repo_type = shift; - - my %args = @_; - - my $username = $self->_get_username(); - my $users_dir = $self->_get_users_dir(); - my $template_dir = $self->_get_template_dir(); - my $sandbox = "$users_dir/$username"; - my @vcs_commands = split (/ /, $vcs_commands ); - - if (! $sandbox) { - return "A sandbox must be defined."; - exit 1; - } - - my $content = HTML::Template->new( filename => "$template_dir/browse.html" ); - my $location; - - if ($path eq '/') { - $path = ''; - } - - if ($path) { - # Security check, no "/.." allowed mister! - $path =~ s:/\.\.::g; - $location = $path; - } else { - $location = '/'; - } - my @location_link; - push (@location_link, split( /\//, $location )); - my @loop_data = (); - my $count = 0; + my $self = shift; + my $path = shift; + my $progname = shift; + my $vcs_commands = shift; + my $repo_type = shift; + + my %args = @_; + + my $username = $self->_get_username(); + my $users_dir = $self->_get_users_dir(); + my $template_dir = $self->_get_template_dir(); + my $sandbox = "$users_dir/$username"; + my @vcs_commands = split (/ /, $vcs_commands ); + + if (! $sandbox) { + return "A sandbox must be defined."; + exit 1; + } + + my $content = HTML::Template->new( filename => "$template_dir/browse.html" ); + my $location; + + if ($path eq '/') { + $path = ''; + } + if ($path) { + # Security check, no "/.." allowed mister! + $path =~ s:/\.\.::g; + $location = $path; + } else { + $location = '/'; + } + my @location_link; + push (@location_link, split( /\//, $location )); + my @loop_data = (); + my $count = 0; + my @location_full = (); + unless ($count) { my %row_data; @@ -80,120 +82,121 @@ push (@loop_data, \%row_data); $count++; - } - $content->param( + } + $content->param( PROGNAME => $progname, - LOCATION => $location, + LOCATION => $location, LOCATION_LOOP => \@loop_data, - ); + ); - my @return = (); - my @loop_data = (); - my $color0 = "#ccccee"; - my $color1 = "#ffffff"; + my @return = (); + my @loop_data = (); + my $color0 = "#ccccee"; + my $color1 = "#ffffff"; - opendir(SANDBOX, "$sandbox/$path") || die "can't opendir $sandbox/$path : $!"; + opendir(SANDBOX, "$sandbox/$path") || die "can't opendir $sandbox/$path : $!"; my @entries = readdir(SANDBOX); chomp @entries; foreach my $entry (@entries) { - next if ($entry =~ /^.$/); - next if ($entry =~ /^.\.$/); - push @return, $entry; + next if ($entry =~ /^.$/); + next if ($entry =~ /^.\.$/); + push @return, $entry; } - closedir SANDBOX; + closedir SANDBOX; - my $counter=0; - unless ($#return< 0) { + my $counter=0; + unless ($#return< 0) { while (@return) { - my %row_data; - $row_data{ENTRY} = shift @return; - $filename = $row_data{ENTRY}; - my $file = SandWeb::File->new( - location => "$sandbox/$path", - filename => "$filename", - ); - $row_data{FILESIZE} = $file->get_size(); - $row_data{FILEAGE} = $file->get_age(); - if (-d "$sandbox/$path/$filename") { - if ($repo_type eq "CVS") { - next if ($filename =~ /^CVS$/); - } - $row_data{FILETYPE} = "dir"; - $row_data{LINK} = "action=browse_menu&path=$path/$filename"; - if ($counter eq "0") { - $row_data{COLOR} = "$color0"; - } else { - $row_data{COLOR} = "$color1"; - } - } - elsif (-T "$sandbox/$path/$filename") { - $row_data{FILETYPE} = "text"; - $row_data{LINK} = "action=file&filename=$path/$filename"; - if ($counter eq "0") { - $row_data{COLOR} = "$color0"; - } else { - $row_data{COLOR} = "$color1"; - } - } - elsif (-B "$sandbox/$path/$filename") { - $row_data{FILETYPE} = "binary"; - $row_data{LINK} = "action=file&filename=$path/$filename"; - if ($counter eq "0") { - $row_data{COLOR} = "$color0"; - } else { - $row_data{COLOR} = "$color1"; - } - } - else { - $row_data{FILETYPE} = "unknown"; - $row_data{LINK} = "action=file&filename=$path/$filename"; - if ($counter eq "0") { - $row_data{COLOR} = "$color0"; - } else { - $row_data{COLOR} = "$color1"; - } - } - $row_data{LOCATION} = $location; - $row_data{PROGNAME} = $progname; - push(@loop_data, \%row_data); - $content->param(ENTRY_LOOP => \@loop_data); - - if ($counter eq "1") { - $counter = 0; - } else { - $counter = 1; - } + my %row_data; + $row_data{ENTRY} = shift @return; + my $entryname = $row_data{ENTRY}; + my $file = SandWeb::File->new( + location => "$sandbox/$path", + filename => "$entryname", + ); + my $filename = $file->get_filename(); + $row_data{FILESIZE} = $file->get_size(); + $row_data{FILEAGE} = $file->get_age(); + if (-d "$sandbox/$path/$filename") { + if ($repo_type eq "CVS") { + next if ($filename =~ /^CVS$/); + } + $row_data{FILETYPE} = "dir"; + $row_data{LINK} = "action=browse_menu&path=$path/$filename"; + if ($counter eq "0") { + $row_data{COLOR} = "$color0"; + } else { + $row_data{COLOR} = "$color1"; + } + } + elsif (-T "$sandbox/$path/$filename") { + $row_data{FILETYPE} = "text"; + $row_data{LINK} = "action=file&filename=$filename"; + if ($counter eq "0") { + $row_data{COLOR} = "$color0"; + } else { + $row_data{COLOR} = "$color1"; + } + } + elsif (-B "$sandbox/$path/$filename") { + $row_data{FILETYPE} = "binary"; + $row_data{LINK} = "action=file&filename=$filename"; + if ($counter eq "0") { + $row_data{COLOR} = "$color0"; + } else { + $row_data{COLOR} = "$color1"; + } + } + else { + $row_data{FILETYPE} = "unknown"; + $row_data{LINK} = "action=file&filename=$filename"; + if ($counter eq "0") { + $row_data{COLOR} = "$color0"; + } else { + $row_data{COLOR} = "$color1"; + } + } + $row_data{LOCATION} = $location; + $row_data{PROGNAME} = $progname; + push(@loop_data, \%row_data); + $content->param(ENTRY_LOOP => \@loop_data); + + if ($counter eq "1") { + $counter = 0; + } else { + $counter = 1; + } } - } else { + } else { $content->param(STATUS => 'No files.'); - } + } - my @loop_data = (); + my @loop_data = (); - if ($repo_type eq "CVS") { - foreach my $vcs_command (@vcs_commands) { - my %row_data; - $row_data{VCS_CMD} = "$vcs_command"; - push (@loop_data, \%row_data); - } - $content->param( VCS_CMD_LOOP => \@loop_data ); - } + if ($repo_type eq "CVS") { + foreach my $vcs_command (@vcs_commands) { + my %row_data; + $row_data{VCS_CMD} = "$vcs_command"; + push (@loop_data, \%row_data); + } + $content->param( VCS_CMD_LOOP => \@loop_data ); + } - return $content->output; + return $content->output; } sub _get_username { - my $self = shift; - return $self->{'username'}; + my $self = shift; + return $self->{'username'}; } sub _get_users_dir { - my $self = shift; - return $self->{'users_dir'}; + my $self = shift; + return $self->{'users_dir'}; } sub _get_template_dir { - my $self = shift; - return $self->{'template_dir'}; + my $self = shift; + return $self->{'template_dir'}; } |