--- trunk/WebPac.pm 2005/03/13 02:00:35 696 +++ trunk/WebPac.pm 2009/05/25 13:49:51 789 @@ -63,6 +63,10 @@ return $tpl if (! $base_path); + #warn "base_path: $base_path, p: $p, path: $path, tpl: $tpl\n"; + + $p =~ s#/[^/]*$##; + # strip everything to and including base path, leaving only # additional (virtual) path if ($base_path eq "/") { @@ -139,16 +143,37 @@ # my ($pager_prev,$pager_next, $pager_jump) = ('','',''); - my $nav_fmt=qq{ %s }; + sub url_with_params { + my ($q,$text) = @_; + my %param = $q->Vars; + my @p; + foreach my $p ( keys %param ) { + my $v = $param{$p}; + next unless defined $v and length($v) > 0; + if ( $v =~ m{\0} ) { + push @p, $p . '=' . my_unac_string($CHARSET, $_) + foreach (split(/\0/, $v )); + } else { + push @p, $p . '=' . my_unac_string($CHARSET, $v); + } + } + + return + qq{ $text }; + } if ($pager->current_page() > $pager->first_page) { $q->param('PAGER_offset', $pager->current_page - 1); - $pager_prev .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'<<'); + $pager_prev .= url_with_params( $q, '<<'); } if ($pager->previous_set) { $q->param('PAGER_offset', $pager->previous_set); - $pager_prev .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'..'); + $pager_prev .= url_with_params( $q,'..'); } @@ -158,18 +183,18 @@ $pager_jump .= "$p "; } else { $q->param('PAGER_offset', $p); - $pager_jump .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),$p); + $pager_jump .= url_with_params($q,$p); } } if ($pager->next_set) { $q->param('PAGER_offset', $pager->next_set); - $pager_next .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'..'); + $pager_next .= url_with_params($q,'..'); } if ($pager->current_page() < $pager->last_page) { $q->param('PAGER_offset', $pager->current_page + 1); - $pager_next .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'>>'); + $pager_next .= url_with_params($q,'>>'); } $tmpl->param('PAGER_PREV', $pager_prev); @@ -247,14 +272,18 @@ my $full = $q->param('full'); my @persist_vars = ( 'rm', 'persist_search' ); - my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) ); + my $url_params = { + 'rm' => 'results', + 'show_full' => 1, + 'last_PAGER_offset' => ($q->param('PAGER_offset') || 0), + }; my @persist_search_vars; - my @url_params_persist; + 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"); + $url_params_persist->{'persist_search'} = $q->url_param("persist_search"); + $url_params->{'persist_search'} = $q->url_param("persist_search"); } # support parametars "f" and "v" for start @@ -275,19 +304,22 @@ # 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); + $url_params->{"f$i"} = $q->url_param("f$i"); + $url_params_persist->{"f$i"} = $q->url_param("f$i") if ($persist); + + my @v; foreach my $v ($q->url_param("v$i")) { # escape quotes so that phrase search work $v =~ s/"/%22/g; - push @url_params,"v$i=$v"; - push @url_params_persist,"v$i=$v" if ($persist); + push @v, $v; } + $url_params->{"v$i"} = \@v; + $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"); + $url_params->{"e$i"} = $q->url_param("e$i"); +# $url_params_persist->{"e$i"} = $q->url_param("e$i"); } my $wc="*"; # swish wildcard @@ -337,6 +369,7 @@ } } $s =~ s/\*+/*/g; + $s =~ s/[()]//g; # () are used in query language $s = $pre.$s.$post if ($q->param("e$i")); push @swish_q,$s; } @@ -347,8 +380,6 @@ my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); - $tmpl->param('url_params',"?".join("&",@url_params)); - sub esc_html { my $html = shift; $html =~ s/param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); + # used to filter entries in index and swish + my $filter = $q->param("filter"); # construct swish query my $sw_q = join(" and ",@s_arr); if (@path_arr && $q->param('show_full')) { - $sw_q .= "and (swishdocpath=\""; + $sw_q .= " and (swishdocpath=\""; $sw_q .= join("\" or swishdocpath=\"",@path_arr); $sw_q .= "\")"; $tmpl->param('full',1); # show full records +# } elsif (@path_arr && $#path_arr == 0) { +# # I will assume that it's a filter since there isn't show_full +# $filter = shift @path_arr; } elsif ($q->param('show_full')) { # just show full path, no path defined $tmpl->param('full',1); @@ -383,6 +418,13 @@ $tmpl->param('full',0); } + if ($filter) { + $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr); + push @persist_vars, "filter"; + $url_params->{'filter'} = $filter; + $url_params_persist->{'filter'} = $filter; + } + my $swish_msg = ' '; # create new swish instance @@ -407,6 +449,26 @@ $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); + # URL parametars for search results + sub cook_url_params { + my $hash = shift || return; + return join("&", map { + my $var = $_; + if (ref($hash->{$var}) eq 'ARRAY') { + join('&', + map { $var.'='.$_ } @{$hash->{$var}} + ); + } else { + $var."=".$hash->{$var}; + } + } keys %{$hash}); + } + + $tmpl->param('url_params',"?".cook_url_params($url_params)); + $tmpl->param('url_params_paths',"?".cook_url_params($url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); + + + # # build pager # @@ -440,7 +502,8 @@ rank => $result->Property('swishrank') }; - $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full')); + #$r->{html} = back2html($from_utf8->convert($result->Property('html')), cook_url_params($url_params_persist)) if ($q->param('show_full')); + $r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full')); push @pager_data_list, $r; }