Permalink
Cannot retrieve contributors at this time
62 lines (56 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/&/&/g; | |
| $value =~ s/>/>/g; | |
| $value =~ s/</</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; |