#!/GWD/bioinfo/apps/bin/perl # # Author: TWiki:Main.CraigMeyer # Date: Jan-23-2007 # package SuggestTopic; use strict; use CGI::Thin; use DirHandle; BEGIN { use vars qw( $DATA_DIR $START_LIST $END_LIST $START_ITEM $END_ITEM $LINE_LIMIT ); # Note: The limit for how many hits to return $LINE_LIMIT = 10; # Note: Modify the following to suit your installation of TWiki $DATA_DIR = "/local/bixweb/apache/instances/bixweb-ump2.gsk.com.3074/htdocs/tw/data"; # Use These for Scriptaculous.js AutoCompleter $START_LIST = ''; $START_ITEM = '
  • '; $END_ITEM = '
  • '; # These are for Beauscott.com AutoComplete # $START_LIST = ''; # $END_LIST = ''; # $START_ITEM = ''; # $END_ITEM = ''; } # BEGIN sub load_files { my($path, $sep, $pattern) = @_; my($file, @list, $hdir); # print STDERR "[load_files] [$path] [$sep] [$pattern]\n"; $hdir = new DirHandle($path) or die "Can't open dir $path\n"; foreach $file ( $hdir->read() ){ next if( $file eq "." || $file eq ".."); if( -f join($sep, $path, $file) && defined($pattern) && $file =~ m|$pattern|i ){ push(@list, $file); } } $hdir->close(); return(\@list); } # load_files sub Main { my(%form, $path, $topic, $limit); $path = $ENV{SCRIPT_URL}; if( $path =~ m#SuggestTopic/(.*)$# ){ $path = join('/', $DATA_DIR,$1); } else { $path = $DATA_DIR; } %form = &Parse_CGI(); $topic = $form{topic}; # print STDERR "SuggestTopic[$path][$topic]\n"; # print STDERR Dumper(\%ENV), "\n"; # print STDERR Dumper(\%form), "\n"; my($pfiles, $file, $dirmode); $pfiles = load_files($path, '/', qq[^$topic.*.txt\$]); $dirmode = 0; print STDOUT qq[\n], $START_LIST, "\n"; $limit = $LINE_LIMIT; foreach $file ( sort { lc($a) cmp lc($b); } @$pfiles ){ last if( $limit-- <= 0 ); $file =~ s/.txt$//; print STDOUT $START_ITEM, $file, $END_ITEM, "\n"; } print STDOUT $END_LIST, "\n"; } #Main &Main();