X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/4114079ae7f2e8879071e7ae7c535c6e1416abf8..9ba648e57a6e37366c685326c9997c3e643ce1ef:/modules/Command.pm
diff --git a/modules/Command.pm b/modules/Command.pm
index ad660c3..6b413d0 100644
--- a/modules/Command.pm
+++ b/modules/Command.pm
@@ -6,41 +6,64 @@ package Command;
# Execute Dev-Editor's commands
#
# Author: Patrick Canterino
\n\n\n";
+ $output .= "
\n\n\n";
# Create the link to the upper directory
# (only if we are not in the root directory)
@@ -83,10 +106,10 @@ sub exec_show($$$)
$output .= " [SUBDIR] ";
$output .= strftime("%d.%m.%Y %H:%M",localtime($stat[9]));
$output .= " " x 10;
- $output .= "../\n";
+ $output .= "../\n";
}
- # Get the longest file/directory name
+ # Get the length of the longest file/directory name
my $max_name_len = 0;
@@ -100,21 +123,24 @@ sub exec_show($$$)
foreach my $dir(@$dirs)
{
- my @stat = stat($physical."/".$dir);
+ my @stat = stat($physical."/".$dir);
+ my $virt_path = encode_entities($virtual.$dir."/");
$output .= " ";
$output .= "[SUBDIR] ";
- $output .= strftime("%d.%m.%Y %H:%M",localtime($stat[9]));
+ $output .= strftime($config->{'timeformat'},localtime($stat[9]));
$output .= " " x 10;
- $output .= "".encode_entities($dir)."/\n";
+ $output .= "".encode_entities($dir)."/";
+ $output .= " " x ($max_name_len - length($dir) - 1)."\t (";
+ $output .= "Work with directory)\n";
}
# Files
foreach my $file(@$files)
{
- my $phys_path = $physical."/".$file; # Not exactly...
- my $virt_path = $virtual.$file;
+ my $phys_path = $physical."/".$file;
+ my $virt_path = encode_entities($virtual.$file);
my @stat = stat($phys_path);
my $in_use = $data->{'uselist'}->in_use($virtual.$file);
@@ -122,34 +148,74 @@ sub exec_show($$$)
$output .= " " x (10 - length($stat[7]));
$output .= $stat[7];
$output .= " ";
- $output .= strftime("%d.%m.%Y %H:%M",localtime($stat[9]));
- $output .= ($in_use) ? " (IN USE) " : (-B $phys_path) ? " (BINARY) " : " " x 10;
+ $output .= strftime($config->{'timeformat'},localtime($stat[9]));
+ $output .= " " x 10;
$output .= encode_entities($file);
$output .= " " x ($max_name_len - length($file))."\t (";
- $output .= (-T $phys_path)
- ? "View"
- : 'View';
+ # Link "View"
+
+ if(-r $phys_path && -T $phys_path)
+ {
+ $output .= "View";
+ }
+ else
+ {
+ $output .= 'Edit'
- : "Edit";
+ # Link "Edit"
+
+ if(-w $phys_path && -r $phys_path && -T $phys_path && not $in_use)
+ {
+ $output .= "Edit";
+ }
+ else
+ {
+ $output .= 'Do other stuff)\n";
+ $output .= '">Edit';
+ }
+
+ # Link "Do other stuff"
+
+ $output .= " | Work with file)\n";
}
$output .= "
\n\n
\n\n";
+
+ # Bottom of directory listing
+ # (Fields for creating files and directories)
+
$output .= <
+
@@ -161,19 +227,23 @@ END
{
# View a file
+ return error("You have not enough permissions to view this file.",upper_path($virtual)) unless(-r $physical);
+
# Check on binary files
+ # We have to do it in this way, or empty files
+ # will be recognized as binary files
- if(-B $physical)
+ unless(-T $physical)
{
# Binary file
- return error("This editor is not able to view/edit binary files.");
+ return error("This editor is not able to view/edit binary files.",upper_path($virtual));
}
else
{
# Text file
- $output = htmlhead("Contents of file $virtual");
+ $output = htmlhead("Contents of file ".encode_entities($virtual));
$output .= equal_url($config->{'httproot'},$virtual);
$output .= dir_link($virtual);
@@ -186,7 +256,7 @@ END
}
}
- return \$output
+ return \$output;
}
# exec_beginedit
@@ -205,16 +275,17 @@ sub exec_beginedit($$)
my $virtual = $data->{'virtual'};
my $uselist = $data->{'uselist'};
- return error("You cannot edit directories.") if(-d $physical);
+ return error("You cannot edit directories.",upper_path($virtual)) if(-d $physical);
return error_in_use($virtual) if($uselist->in_use($virtual));
+ return error("You have not enough permissions to edit this file.",upper_path($virtual)) unless(-r $physical && -w $physical);
# Check on binary files
- if(-B $physical)
+ unless(-T $physical)
{
# Binary file
- return error("This editor is not able to view/edit binary files.");
+ return error("This editor is not able to view/edit binary files.",upper_path($virtual));
}
else
{
@@ -223,27 +294,33 @@ sub exec_beginedit($$)
$uselist->add_file($virtual);
$uselist->save;
- my $dir = upper_path($virtual);
- my $content = encode_entities(${file_read($physical)});
+ my $dir = upper_path($virtual);
+ my $content = encode_entities(${file_read($physical)});
+
+ my $equal_url = equal_url($config->{'httproot'},$virtual);
+
+ $virtual = encode_entities($virtual);
my $output = htmlhead("Edit file $virtual");
- $output .= equal_url($config->{'httproot'},$virtual);
+ $output .= $equal_url;
$output .= <Create new file:
-$virtual
+