8 |
use Template; |
use Template; |
9 |
use List::Util qw/first/; |
use List::Util qw/first/; |
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
use URI::Escape qw/uri_escape_utf8/; |
use Encode; |
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
14 |
|
|
16 |
|
|
17 |
=head1 VERSION |
=head1 VERSION |
18 |
|
|
19 |
Version 0.03 |
Version 0.06 |
20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
our $VERSION = '0.03'; |
our $VERSION = '0.06'; |
24 |
|
|
25 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
26 |
|
|
145 |
|
|
146 |
filter to return links to search, usage in TT: |
filter to return links to search, usage in TT: |
147 |
|
|
148 |
[% search('FieldToDisplay','FieldToSearch','optional delimiter') %] |
[% search('FieldToDisplay','FieldToSearch','optional delimiter', 'optional_template.tt') %] |
149 |
|
|
150 |
=cut |
=cut |
151 |
|
|
157 |
|
|
158 |
return sub { |
return sub { |
159 |
|
|
160 |
my ($display,$search,$delimiter) = @_; |
my ($display,$search,$delimiter,$template) = @_; |
161 |
|
|
162 |
# default delimiter |
# default delimiter |
163 |
$delimiter ||= '¶<br/>', |
$delimiter ||= '¶<br/>', |
198 |
$s = $item->{'search'}->[0]; |
$s = $item->{'search'}->[0]; |
199 |
} |
} |
200 |
#$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg; |
#$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg; |
201 |
$s = uri_escape_utf8( $s ); |
$s = __quotemeta( $s ); |
202 |
|
|
203 |
my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display"; |
my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display"; |
204 |
|
|
205 |
push @html, <<__JS_LINK_SEARCH__ |
my $template_arg = ''; |
206 |
<a href="#" onclick="new Ajax.Updater( 'results', '/search/results?$search=$s', { asynchronous: 1,onLoading: function(request){show_searching();},onLoaded: function(request){hide_searching();} } ) ; return false">$d</a> |
$template_arg = qq{,'$template'} if ($template); |
207 |
__JS_LINK_SEARCH__ |
|
208 |
|
push @html, qq{<a href="#" onclick="return search_via_link('$search','$s'${template_arg})">$d</a>}; |
209 |
} |
} |
210 |
|
|
211 |
return join($delimiter, @html); |
return join($delimiter, @html); |
263 |
$args->{'load_template'} = sub { |
$args->{'load_template'} = sub { |
264 |
my $template = shift or return "Logger.error('load_template missing template name!'); return false;"; |
my $template = shift or return "Logger.error('load_template missing template name!'); return false;"; |
265 |
return "load_template($template); return false;"; |
return "load_template($template); return false;"; |
266 |
} |
}; |
267 |
|
|
268 |
my $out; |
my $out; |
269 |
|
|
311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
|
=head2 __quotemeta |
315 |
|
|
316 |
|
Helper to quote JavaScript-friendly characters |
317 |
|
|
318 |
|
=cut |
319 |
|
|
320 |
|
sub __quotemeta { |
321 |
|
local $_ = shift; |
322 |
|
$_ = decode('iso-8859-2', $_); |
323 |
|
|
324 |
|
s<([\x{0080}-\x{fffd}]+)>{sprintf '\u%0*v4X', '\u', $1}ge if ( Encode::is_utf8($_) ); |
325 |
|
{ |
326 |
|
use bytes; |
327 |
|
s<((?:[^ \x21-\x7E]|(?:\\(?!u)))+)>{sprintf '\x%0*v2X', '\x', $1}ge; |
328 |
|
} |
329 |
|
|
330 |
|
s/\\x09/\\t/g; |
331 |
|
s/\\x0A/\\n/g; |
332 |
|
s/\\x0D/\\r/g; |
333 |
|
s/"/\\"/g; |
334 |
|
s/\\x5C/\\\\/g; |
335 |
|
|
336 |
|
return $_; |
337 |
|
} |
338 |
|
|
339 |
=head1 AUTHOR |
=head1 AUTHOR |
340 |
|
|
341 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |