Skip to content
Permalink
3.3
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
use EPrints;
use strict;
use warnings;
my $session = EPrints::Session->new();
my $string_frag = lc $session->param( "q" );
my $lookup_file = $session->param( "file" );
my $mode = $session->param( "mode" ) || "phrase";
if( !defined $lookup_file )
{
EPrints::abort( "no filename" );
}
$lookup_file=~s/\///sg;
$lookup_file=~s/^\.+//s;
my $filepath = $session->config( "config_path" )."/autocomplete/$lookup_file";
open( DATA, '<', $filepath ) || EPrints::abort "can't read $filepath: $!";
my @filtered_lookup_names;
if( $mode eq "phrase" )
{
@filtered_lookup_names = grep
{ index( lc($_), $string_frag ) != -1 }
<DATA>;
}
if( $mode eq "prefix" )
{
my $l = length $string_frag;
@filtered_lookup_names = grep
{ lc(substr( $_, 0, $l )) eq $string_frag }
<DATA>;
}
close DATA;
print <<END;
<?xml version="1.0" encoding="UTF-8" ?>
END
print '<ul>';
my $togo = 20;
my $first = 1;
foreach my $value ( @filtered_lookup_names )
{
chomp $value;
$value =~ s/&/&amp;/g;
$value =~ s/>/&gt;/g;
$value =~ s/</&lt;/g;
print "<li";
if( $first )
{
print " class='ep_first'";
}
print ">$value";
print "<ul><li id='for:value:relative:'>$value</li></ul>";
print "</li>";
$first= 0;
--$togo;
last unless $togo;
}
print '</ul>';
$session->terminate;