From: Dobrica Pavlinusic Date: Tue, 18 Jan 2005 17:07:14 +0000 (+0000) Subject: Implemented persist_search hidden variable in forms which can specify X-Git-Url: http://git.rot13.org/?p=webpac;a=commitdiff_plain;h=5bd22bec41221e9d5f8b10c570f542898ff6d106 Implemented persist_search hidden variable in forms which can specify (multiple) number of variables which should be persistent after user specified them in form (useful for language for example). Values are separated by comma (,). Some cleanup and warning removal. git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@636 13eb9ef6-21d5-0310-b721-a9d68796d827 --- diff --git a/WebPac.pm b/WebPac.pm index d6337b3..4375ea5 100644 --- a/WebPac.pm +++ b/WebPac.pm @@ -184,12 +184,13 @@ sub make_pager_vars { my $hidden_vars = ''; foreach my $v (@persist_vars) { foreach my $val ($q->param($v)) { + next if (! $val || $val eq ''); $hidden_vars .= ''."\n"; } } $tmpl->param('PAGER_HIDDEN', $hidden_vars); - $tmpl->param('PAGER_JAVASCRIPT', qq{ + $tmpl->param('PAGER_JAVASCRIPT', qq# - }); + #); } #-------------------------------------------------------------------------- @@ -230,26 +231,47 @@ sub show_results_list { my @path_arr = $q->param('path'); my $full = $q->param('full'); - my @persist_vars = ( 'rm' ); + my @persist_vars = ( 'rm', 'persist_search' ); my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) ); + my @persist_search_vars; + my @url_params_persist; + if ($q->param("persist_search")) { + @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search")); + push @url_params_persist, "persist_search=".$q->url_param("persist_search"); + push @url_params,"persist_search=".$q->url_param("persist_search"); + } + # support parametars "f" and "v" for start - for(my $i = ""; $i <=30; $i++) { + for(my $i = 0; $i <=30; $i++) { + + $i = '' if ($i == 0); return show_index($self, $i) if ($q->param("f".$i."_index")); - next if (! $q->param("v$i")); + next if (! $q->param("v$i") || $q->param("v$i") eq ''); next if (! $q->param("f$i")); + my $persist = grep(/^$i$/,@persist_search_vars); + push @persist_vars, "f$i"; push @persist_vars, "v$i"; push @persist_vars, "e$i" if ($q->param("e$i")); + # create url parametars (and persistent ones) + push @url_params,"f$i=".$q->url_param("f$i"); + push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); + foreach my $v ($q->url_param("v$i")) { push @url_params,"v$i=$v"; + push @url_params_persist,"v$i=$v" if ($persist); + } + + if ($q->param("e$i")) { + push @url_params,"e$i=".$q->url_param("e$i"); + push @url_params_persist,"e$i=".$q->url_param("e$i"); } - push @url_params,"e$i=".$q->url_param("e$i"); my $wc="*"; # swish wildcard $wc="" if ($i eq ""); # don't apply wildcard on field 0 @@ -270,8 +292,9 @@ sub show_results_list { # filed e[nr] is exact match bitmask # 1 = beginning, 2=end, 3=both - $pre = '"xxbxx ' if ($q->param("e$i") & 1); - $post = ' xxexx"' if ($q->param("e$i") & 2); + my $exact_flag = $q->param("e$i") || 0; + $pre = '"xxbxx ' if ($exact_flag & 1); + $post = ' xxexx"' if ($exact_flag & 2); # add qotes on other side if ($q->param("e$i")) { $pre = '"' if (! $pre); @@ -324,13 +347,12 @@ sub show_results_list { # construct swish query my $sw_q = join(" and ",@s_arr); - if (@path_arr) { + if (@path_arr && $q->param('show_full')) { $sw_q .= "and (swishdocpath=\""; $sw_q .= join("\" or swishdocpath=\"",@path_arr); $sw_q .= "\")"; - } - - if ($q->param('show_full')) { + $tmpl->param('full',1); # show full records + } elsif ($q->param('show_full')) { # just show full path, no path defined $tmpl->param('full',1); } else { @@ -390,7 +412,7 @@ sub show_results_list { rank => $result->Property('swishrank') }; - $r->{html} = back2html($from_utf8->convert($result->Property('html'))) if ($q->param('show_full')); + $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full')); push @pager_data_list, $r; } diff --git a/back2html.pm b/back2html.pm index 860a1d6..0fcf931 100644 --- a/back2html.pm +++ b/back2html.pm @@ -6,6 +6,7 @@ sub back2html { my $html = shift; + my $url_params = shift; $html =~ s//>/g; @@ -16,7 +17,7 @@ sub back2html { # convert spaces in left field to non-breaking spaces $items[0] =~ s#\s+# #g; # try to make link on right field - sub mkurl { + sub mkurl($) { my $url = shift || die "mkurl needs url as argument"; # chop URLS longer than 60 characters my $txturl = substr($1,0,60); @@ -30,7 +31,16 @@ sub back2html { # put
back into html $out =~ s,<br/*>,
,gi; # put yyyy back into html - $out =~ s,<(a\s+href=)(.+?)>(.+?)<(/a)>,<$1$2>$3<$4>,gsi; + sub mkurl_param($$$$) { + my ($a_href,$url,$text,$a_end) = @_; + if ($url =~ m#\?#) { + $url .= "&".$url_params; + } else { + $url .= "?".$url_params; + } + return '<'.$a_href.'"'.$url.'">'.$text.'<'.$a_end.'>'; + } + $out =~ s#<(a\s+href=)['"]*(.+?)['"]*>(.+?)<(/a)>#mkurl_param($1,$2,$3,$4)#gsie; return $out; } diff --git a/template_html/search.html b/template_html/search.html index a293fec..b2e83ce 100644 --- a/template_html/search.html +++ b/template_html/search.html @@ -37,6 +37,7 @@
+
Pretra¾i sve: