From: pcanterino <> Date: Sun, 26 Dec 2004 12:13:57 +0000 (+0000) Subject: - Allow to filter directory listing using DOS-style wildcards (maybe it still X-Git-Tag: version_2_3~14 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/bcb55273938af55f30b100d396f0a0cfda990bce?ds=inline - Allow to filter directory listing using DOS-style wildcards (maybe it still needs work for being more usable) - Fixed a typo in File::Access --- diff --git a/modules/Command.pm b/modules/Command.pm index 6c02aa1..fb0997c 100644 --- a/modules/Command.pm +++ b/modules/Command.pm @@ -6,7 +6,7 @@ package Command; # Execute Dev-Editor's commands # # Author: Patrick Canterino -# Last modified: 2004-12-21 +# Last modified: 2004-12-26 # use strict; @@ -20,7 +20,9 @@ use File::Path; use POSIX qw(strftime); use Tool; -use CGI qw(header); +use CGI qw(header + escape); + use HTML::Entities; use Output; use Template; @@ -110,6 +112,9 @@ sub exec_show($$) my $dirlist = ""; + my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard + my $filter2 = ($filter1 && $filter1 ne '*') ? $filter1 : ''; # Wildcard for output + # Create the link to the upper directory # (only if we are not in the root directory) @@ -130,6 +135,8 @@ sub exec_show($$) foreach my $dir(@$dirs) { + next unless(dos_wildcard_match($filter1,$dir)); + my $phys_path = $physical."/".$dir; my $virt_path = encode_entities($virtual.$dir."/"); @@ -153,6 +160,8 @@ sub exec_show($$) foreach my $file(@$files) { + next unless(dos_wildcard_match($filter1,$file)); + my $phys_path = $physical."/".$file; my $virt_path = encode_entities($virtual.$file); @@ -193,7 +202,11 @@ sub exec_show($$) $tpl->fillin("SCRIPT",$script); $tpl->fillin("URL",encode_entities(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin("FILTER",encode_entities($filter2)); + $tpl->fillin("FILTER_URL",escape($filter2)); + $tpl->parse_if_block("dir_writeable",$dir_writeable); + $tpl->parse_if_block("filter",$filter2); } else { diff --git a/modules/File/Access.pm b/modules/File/Access.pm index 31377d9..8958e62 100644 --- a/modules/File/Access.pm +++ b/modules/File/Access.pm @@ -3,8 +3,8 @@ package File::Access; # # Dev-Editor - Module File::Access # -# Some simple routines for doing things with files -# with only one command +# Some simple routines for doing things with files by +# using only one command # # Author: Patrick Canterino # Last modified: 2004-12-17 diff --git a/modules/Tool.pm b/modules/Tool.pm index 6a615da..e261f3e 100644 --- a/modules/Tool.pm +++ b/modules/Tool.pm @@ -6,7 +6,7 @@ package Tool; # Some shared sub routines # # Author: Patrick Canterino -# Last modified: 2004-12-16 +# Last modified: 2004-12-25 # use strict; @@ -28,6 +28,7 @@ use base qw(Exporter); @EXPORT = qw(check_path clean_path devedit_reload + dos_wildcard_match equal_url file_name mode_string @@ -159,6 +160,30 @@ sub devedit_reload(;$) return \$header; } +# dos_wildcard_match() +# +# Check if a string matches against a DOS-style wildcard +# +# Params: 1. Pattern +# 2. String +# +# Return: Status code (Boolean) + +sub dos_wildcard_match($$) +{ + my ($pattern,$string) = @_; + + # The following part is stolen from File::DosGlob + + # escape regex metachars but not glob chars + $pattern =~ s:([].+^\-\${}[|]):\\$1:g; + # and convert DOS-style wildcards to regex + $pattern =~ s/\*/.*/g; + $pattern =~ s/\?/.?/g; + + return ($string =~ m|^$pattern$|is); +} + # equal_url() # # Create URL equal to a file or directory diff --git a/templates/dirlist.htm b/templates/dirlist.htm index 2db1617..8a8c9ee 100644 --- a/templates/dirlist.htm +++ b/templates/dirlist.htm @@ -47,11 +47,28 @@ + +
+ + - + + + - + + + + + + + + + + +
Go to directory/file: Go to directory/file: About Dev-Editor
Filter:
+
About Dev-Editor
diff --git a/templates/dirlist_dir.htm b/templates/dirlist_dir.htm index cfac797..2162e2e 100644 --- a/templates/dirlist_dir.htm +++ b/templates/dirlist_dir.htm @@ -1,6 +1,6 @@ [SUBDIR] {DATE} -{IF readable}{DIR_NAME}/{ELSE}{DIR_NAME}/{ENDIF} +{IF readable}{DIR_NAME}/{ELSE}{DIR_NAME}/{ENDIF} ({IF dir_writeable}Rename | Delete | {ENDIF}{IF users}Chmod/Chgrp | {ENDIF}View in Browser) diff --git a/templates/dirlist_up.htm b/templates/dirlist_up.htm index 5f375e5..0384c0d 100644 --- a/templates/dirlist_up.htm +++ b/templates/dirlist_up.htm @@ -1,5 +1,5 @@ [SUBDIR] {DATE} -../ +../